Google Analytics Cross Domain Not Working

After setting up the Cross Domain parameters properly, using _setDomainName(), _setAllowHash(), and _setAllowLinker(), and making sure to call the _trackPageview() last,  using ga_debug.js in Chrome, I was able to see that the AccountID and the SessionID were still changing upon navigating to the other Domain.

This meant the cookies were not being shared across the Domains using the _link() method from Google Analytics Asynchronous Library.

So what is the [workaround]?

After carefully studying how one would implement inline code to enable _link(), I realized I was missing a return false statement.  For inline code, the return false is used to prevent the Default Event of the anchor tag from occurring to the navigation source of the href attribute.  Using jQuery in an Unobtrusive JavaScript Library, without the return false statement, the _link() method just does not work:

$(‘a’).click(function () {
     var
href = $(this).attr(‘href’);
     if (href.indexOf(OtherDomainName) >  –1)  {
          _gaq.push([‘_link’, href]);

          return false;
     }
      return href;
});

And Voila!  Problem solved!

Windows Live Tags: Google Analytics,_link(),Cross Domain Tracking,Unobtrusive JavaScript

Print | posted on Wednesday, August 17, 2011 7:41 PM

Feedback

# re: Google Analytics Cross Domain Not Working

Left by Weiz at 3/1/2012 3:42 AM
Gravatar use preventDefualt() before calling _link(), it will work even under jquery

Your comment:





 
 

Copyright © intermark

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski