_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

John is a former LunaMetrician and contributor to our blog.

  • http://ourrug.net/ Russell Smith

    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.

Contact Us.

LunaMetrics

24 S. 18th Street, Suite 100,
Pittsburgh, PA 15203

Follow Us

1.877.220.LUNA

1.412.381.5500

getinfo@lunametrics.com

Questions?
We'll get back to you
in ONE business day.