Sun, 10 Feb 2008

Multi-Domain Tracking with Google Analytics/Urchin Tracking

If you are trying to track multiple domains within the same Google Analytics or Urchin profile, make sure you are using the same tracking library on all sites. I was attempting to track a visitor from one site using urchin.js to another using ga.js, and I spent a few hours trying to figure out why it wasn't working.

It turns out that the cookie data is encoded differently in query string appended to the url of the site to which you are passing it. With urchin.js and __utmLinker(), the __utmz cookie is url-encoded, but not with ga.js and ._link(). Compare the two URLs below.

http://example.com/?__utma=1.1181041260.1202679736.1202679736.1202679736.1&__utmb=1&__utmc=1.0&__utmx=-&__utmz=1.1202680382.1.3.utmcsr%3DFake%2BSource%7Cutmccn%3Dbogus%7Cutmcmd%3Dclicky%2Bclicky&__utmv=-&__utmk=129628685
http://example.com/?__utma=1.1181041260.1202679736.1202679736.1202679736.1&__utmb=1.0&__utmc=1.0&__utmx=-&__utmz=1.1202680287.1.2.utmcsr=Fake%2BSource|utmccn=bogus|utmcmd=clicky%2Bclicky&__utmv=-&__utmk=54196648

The ga.js _initData() won't properly parse the __utmz data from the query string in the first example. I hope this saves someone else some time.

tech | Permanent Link

The state is that great fiction by which everyone tries to live at the expense of everyone else. - Frederic Bastiat