最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cross-domain tracking for subdomains with Google Analytics - Stack Overflow

programmeradmin1浏览0评论

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: .py?page=guide.cs&guide=1034143&topic=1033979

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

one.mysite
two.mysite
three.mysite

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']); // used on one.mysite
_gaq.push(['_setDomainName', 'two.mysite']); // used on two.mysite
_gaq.push(['_setDomainName', 'three.mysite']); // used on three.mysite

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./analytics/bin/static.py?page=guide.cs&guide=1034143&topic=1033979

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

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

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.']); // used on one.mysite.
_gaq.push(['_setDomainName', 'two.mysite.']); // used on two.mysite.
_gaq.push(['_setDomainName', 'three.mysite.']); // used on three.mysite.
Share Improve this question edited Jun 14, 2013 at 4:11 Yahel 37.3k23 gold badges106 silver badges154 bronze badges asked Dec 9, 2011 at 14:41 diggersworlddiggersworld 13.1k25 gold badges86 silver badges120 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

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.), all you need to do is set your domain name to the root of your domain like so:

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

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

 _gaq.push(['_setDomainName', '.mysite.']); // used on any mysite. 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.)

发布评论

评论列表(0)

  1. 暂无评论