Question

I got one domain set up with multiple Google Analytic accounts. The site has different events which were properly tracked in the first profile. But … i'd like to have the events passed to each account without creating an onclick event for each profile.

<script type="text/javascript">
var _gaq = _gaq || [];

_gaq.push(
    ['_setAccount', 'UA-xxxxxxx30-1'], ['_trackPageview'],  ['_gat._anonymizeIp'],
    ['b._setAccount', 'UA-xxxxxxx33-1'], ['_trackPageview'], ['_gat._anonymizeIp'],
    ['c._setAccount', 'UA-xxxxxxx76-1'], ['_trackPageview'], ['_gat._anonymizeIp']
);


(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

Thanks for your support Mike

Was it helpful?

Solution

First, the code snippet you pasted is not correct. The _trackPageview call that follows each tracker will fire a _trackPageview for the first tracker object only. Additionally, your _anonymizeIp setting is being incorrectly used as it needs to come before the first _trackPageview and it applies to all tracker objects.

Corrected syntax:

_gaq.push(
    ['_setAccount', 'UA-xxxxxxx30-1'], ['_gat._anonymizeIp'], ['_trackPageview'],
    ['b._setAccount', 'UA-xxxxxxx33-1'], ['b._trackPageview'],
    ['c._setAccount', 'UA-xxxxxxx76-1'], ['c._trackPageview']
);

For event tracking, you could create a function that does an event tracking call out to all of your trackers in one function call. Something like:

function gaTrackEventAllTrackers(category,action,optLabel,optValue,optInteraction) {
    _gaq.push(
        ['_trackEvent',category,action,optLabel,optValue,optInteraction],
        ['b._trackEvent',category,action,optLabel,optValue,optInteraction],
        ['c._trackEvent',category,action,optLabel,optValue,optInteraction]
    );
}

Then just call this function in your code or onclick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top