How do I transfer one event to two different Google Analytics accounts?
I have implemented the following on my site to transfer the event to two Google Analytics accounts.
There are two different accounts in my GA-Tracking code in the chapter section :
_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 only clicks on the event to the UA-XXXXX1-1 account (as expected) to both accounts! Why?!?!
Anyone who can help?
-Thank
EDIT
This is a new implementation I tested as 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>
source to share
_trackPageview
and _trackEvent
work by requesting a tracking pixel from Google Analytics servers - if your link opens a new page in the same window or triggers a load, then the browser may cancel the tracking pixel requests prematurely before the data can be captured, and you're lucky the first request passed.
A common solution is to delay the processing of the link for a short amount of time (eg 150ms) to allow requests to be processed.
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>
source to share