Google Analytics - cross domain tracking

You can track a user across domains with Google Analytics by adding an onclick event to the link. The _setAllowLinker() function tracks user clicks between two domains. See the related links for information on other scenarios, eg. tracking across iFrames. 

_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']); 
... 
​<a href="http://example.com/test.html" onclick="_gaq.push(['_link', 'http://example.com/test.html']); return false;">click me</a>

If you want to add the onclick event to the link dynamically via jQuery, see this post about adding Google event tracking with jQuery

 

HINT

If you want to use one push to add multiple commands put the cross domain bit last. For instance if you want to add an event tracker to the link you would do it like this:

_gaq.push(
   ['_trackEvent', 'Button Clicked', 'Click', 'Link to other domain'],
   ['_link', 'http://example.com/test.html']
);
​​return false;

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.