_initData() — Always there, or always not.

During 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

Share and Enjoy:
  • Print
  • email
  • Digg
  • Reddit
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Facebook
  • Twitter

Related Posts

  1. Cross-domain tracking and _setVar
  2. Using Different Cookies when Tracking to Multiple Accounts in GA
  3. Pitfalls of tracking to multiple accounts in GA
  4. Dot or Not
  5. Bounce rate and the _setVar('…'); — what is the relationship?

One Response to “_initData() — Always there, or always not.”

Thanks for pointing this out!! I’ve also noticed this discrepancy and wondered why it’s used on some sites and not on others; I just assumed it was depreciated.

Leave a Reply

Feedback Form