0

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

mikeg
  • 55
  • 7

1 Answers1

0

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.

  • Your tip with the _gat._anonymizeIp was very helpful. I haven't found any documentation in the Google docs about this. Neverless the enhanced code results in an absolute non tracking in any profile. I checked the code with the testing widget from Google and the cookies were just fine. Wired … Regarding to the function, providing the variables to each profile without creating a new trackEvent for each account isn't possible, isn't it? Hoped to find a more efficient solution. Thanks a lot – mikeg May 25 '12 at 09:07
  • For the non-tracking issue, I assume you are referring to even pageviews. For that, double check that you are not filtering out your IP, etc in profile settings. You can also look at the Real Time feature to see if you see your pageviews. If you wish to share your URL I can double check things from a code perspective. I don't follow your comment about the event tracking function, so if you can provide more information that would be helpful. – Joe Christopher May 25 '12 at 14:53
  • Wired. Two people implemented exactly the same code. First results in 100% data loss, second one goes just fine. Exept the last GA-String. – mikeg May 30 '12 at 06:58
  • EDIT: Wired … two people implemented exactly the same code. First results in 100% data loss, second one goes just fine. The first two accounts now track everything just perfect. Real-Time works in all three accounts but in the last one, the standard reports doesn't show any data. http://bit.ly/LEm7Su Thanks a lot Mike – mikeg May 30 '12 at 07:05
  • The code on your site looks fine and I'm seeing tracking pixels for all 3 trackers successfully fire. I would suggest confirming that the UA-#s are correct (especially for the one that is not showing in real-time) and then also check your profile filters to make sure that you don't have something in there that would be excluded some/all hits. Another tip would be to move this code up into the as where it is now it doesn't fire until several seconds after the page loads due to the size of this page. – Joe Christopher May 30 '12 at 14:59
  • The GA-UA matches and there're no filters which excludes traffic. I swapped the code to the head a couple of hours ago. Everything stayed the same in the last profile. – mikeg May 31 '12 at 08:58