Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-domain tracking for subdomains with Google Analytics

I've just setup google analytics cross domain tracking.
I've seen a few example of it but would like to make sure I've done it correctly.
The documentation I followed is here: http://support.google.com/analytics/bin/static.py?page=guide.cs&guide=1034143&topic=1033979

I basically have 3 websites which are all sub-domains.

one.mysite.com
two.mysite.com
three.mysite.com

I have added the following lines to the default Analytics script and made sure I use the same value for _setAccount.

_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);

Now... the part that I'm slightly confused about is the _setDomainName variable.

Am I supposed to leave it as "none" on all three websites and let the _setAllowLinker to do the work or am I mean to specify the domains individually like below?

_gaq.push(['_setDomainName', 'one.mysite.com']); // used on one.mysite.com
_gaq.push(['_setDomainName', 'two.mysite.com']); // used on two.mysite.com
_gaq.push(['_setDomainName', 'three.mysite.com']); // used on three.mysite.com
like image 375
diggersworld Avatar asked Dec 09 '11 14:12

diggersworld


1 Answers

For cross subdomain traffic, you do not need to set _setAllowLinker, though there's no harm. What that function does is enable the ability to transfer your Google Analytics cookies for cross domain tracking. That functionality, enabled by the function _link, is not necessary for your use case.

If you set your setDomainName to none like that, what it does is it sets the domain hash to 1 and sets the domain of the cookies to the current domain. This does not help you for cross subdomain tracking, as traffic between subdomains will be treated as referrals.

If you don't have third level subdomains to track (like foo.bar.example.com), all you need to do is set your domain name to the root of your domain like so:

 _gaq.push(['_setDomainName', 'mysite.com']); // used on any mysite.com domain or subdomain

If you think you'll need 3rd level subdomain tracking, you should put a leading period in front of mysite.com, like so:

 _gaq.push(['_setDomainName', '.mysite.com']); // used on any mysite.com domain or subdomain as well as third level subdomains

What you're doing here is two things. One, you're declaring what domain the cookies should be set at (in this case, the above 2 domains are identical) and you're configuring what domain will be used to create your "domain hash", which is the first period delimited value in the Google Analytics cookie. Google Analytics uses the "domain hash" to prevent cookie conflicts; if the domain hash of the value you've configured in setDomainName isn't consistent with the one at the start of the cookies that ga.js detects, it'll create a new set of cookies and create an entirely new visit (which, in your case, is not what you want.)

like image 127
Yahel Avatar answered Sep 30 '22 13:09

Yahel