google analytics - multiple trackers on one page (cookie conflict)

Viewed 59828

I'm writing a web application that's supposed to be embedded in other people's websites (kind of a widget). I'm using Google Analytics to track all the people that visit all instances of my script on the embedding websites. The problem is that I don't know how to use it so that it doesn't interfere with those websites' own Google Analytics accounts. I'm storing the tracker variable in a namespace, so I thought that should do it, but I haven't realized that GA stores its settings in cookies (__utma, __utmz etc.), and those cookies are used by both trackers, if there are two of them on the same page... So for example if I use _setVar to store some kind of user-defined variable in Google Analytics, and the embedding site does the same, we overwrite each other's values...

Of course it would be easiest if Google provided a way to change the name of the cookies to a custom one, but I can't find any way to do it. I thought about using cookie domain or path to force a separate cookie, but this doesn't work, because if I set domain or path to something other than the real domain/path, then the cookie is not readable for the page after reload...

Does anyone know a way to have two trackers on one page and make them use separate cookies so that they don't overwrite each other's settings?

Or, if that's completely impossible - is there any other analytics service with similar functionality as GA in which this is possible? (it would have to have advanced features like event and campaign tracking...)

9 Answers

I have used this structure on our site and clients sites and it works like a charm...

<script type="text/javascript"> 
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");    
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'     type='text/javascript'%3E%3C/script%3E")); 
</script> <script type="text/javascript"> 

try {

//Original tracking
var pageTracker_ORIG = _gat._getTracker("UA-XXXXXXX-1");
pageTracker_ORIG._setDomainName('.sleepinggiantmedia.co.uk');
pageTracker_ORIG._trackPageview();

//New Analytics tag
var pageTracker_SGM = _gat._getTracker("UA-XXXXXXX-1");
pageTracker_SGM._setDomainName('.sleepinggiantmedia.co.uk');
pageTracker_SGM._trackPageview();


} catch(err) {}

var otherTracker = _gat._getTracker(”UA-22222-1″);
otherTracker._setDomainName(’domain.com’);
otherTracker._trackPageview();

This person is having the same problem on the Google Analytics help fourm. I'd suggest taking a look at the thread. But regularly GA doesn't support multiple trackers.

I like Clicky myself, but it costs money.

Related