_initData() — Always there, or always not.
April 29th, 2009 by JohnDuring some troubleshooting this week, I came across something that some of you may find useful or interesting (or maybe not.)
You may already know that the pageTracker._initData() line in the GATC has been deprecated. It can still be used however, and is often in place on many websites.
But when you call pageTracker._initData() on some pages, and Don’t call it on other pages, that is when you have a problem. It seems that the cookies are written slightly differently when initData is present vs when it is absent. This causes GA to lose track of the visitor, and lose track of how they arrived at your site (Source, Medium, etc).
Make sure you are consistent throughout your site, with pageTracker._initData(), and you should be fine. Either use it everywhere, or use it nowhere.
— Update/Addition/Clarification:—
If you include initData you need to make sure it is placed after any instructions that alter the way GA writes cookies, such as _setAllowHash(false) or _setDomainName(’none’)
Example:
Bad:
var pageTracker = _gat._getTracker(”UA-xxxxxxx-y”);
pageTracker._initData();
pageTracker._setDomainName(”sub.domain.com”);
pageTracker._setAllowHash(false);
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();
Okay:
var pageTracker = _gat._getTracker(”UA-xxxxxxx-y”);
pageTracker._setDomainName(”sub.domain.com”);
pageTracker._setAllowHash(false);
pageTracker._setAllowLinker(true);
pageTracker._initData();
pageTracker._trackPageview();
* Thanks to Charles at Epik One for this addition
———————————–
John
- Cross-domain tracking and _setVar...
- Using Different Cookies when Tracking to Multiple Accounts in GA...
- Dot or Not...
- Bounce rate and the _setVar(’…’); — what is the relationship?...
Related posts brought to you by Yet Another Related Posts Plugin.








I was afraid that with the recession, training wouldn’t be all the rage this year. But one of our Google Analytics training sessions is half-filled already, with six weeks to go.


ice I have experienced. I work with many startups, have consulted for numerous clients, and have called on dozens of vendors. Never once have I seen something this gracious. [Comment from Robbin: He is talking about JOHN? Who insults me every day?]

