Question

I've implemented the following on my site, to pass an Event to two different Google-Analytics accounts.

In my GA-Trackingcode in the head section there are two different accounts defined:

_gaq.push(['_setAccount', 'UA-XXXXX1-1']);   
_gaq.push(['_trackPageview']);  


_gaq.push(['account2._setAccount', 'UA-XXXXX2-1']);
_gaq.push(['account2._trackPageview']);

my event is the following:

<a href="#" onClick="_gaq.push(['_trackEvent', 'Download', 'xyz', 'xyzz'],
['account2._trackEvent', 'Download', 'xyz', 'xyzz']);">
Download_Fible_Fluegas</a>

But the code does only push the Event to the UA-XXXXX1-1 Account not (like i expected) to both accounts! Why?!?!

Someone out there who can help?

-Thanks

EDIT

This is the new implementation which i am testing like Google tells me in their docs https://developers.google.com/analytics/devguides/collection/gajs/?hl=de-DE#MultipleCommands

<a href="#" onClick="_gaq.push(['_setAccount', 'UA-XXXXXXX3-1'], ['_trackEvent', 'Download', 'xyz', 'xyzz'],['account2._setAccount', 'UA-XXXXXXX2-1'],['account2._trackEvent', 'Download', 'xyz', 'xyzz']);">Link_to_download</a>
Was it helpful?

Solution

_trackPageview and _trackEvent work by requesting a tracking pixel from the Google Analytics servers -- if your link is opening a new page in the same window or causing a download, then the browser can be canceling the tracking pixel requests prematurely before data can be captured, and you've been lucky timing-wise that the first request has gone through.

The common solution is to delay the processing of the link by a short amount of time (like 150ms) in order to allow the requests to be made.

Something like

function trackMe(link) {
  _gaq.push(['_trackEvent', 'Download', 'xyz', 'xyzz'], ['account2._trackEvent', 'Download', 'xyz', 'xyzz']);
  setTimeout(function(){document.location = link.href}, 150);
  return false;
}

<a href="#" onClick="return trackMe(this);">Download_Fible_Fluegas</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top