admin管理员组文章数量:1321836
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
1 Answer
Reset to default 9For 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.)
本文标签: javascriptCrossdomain tracking for subdomains with Google AnalyticsStack Overflow
版权声明:本文标题:javascript - Cross-domain tracking for subdomains with Google Analytics - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742104930a2420974.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论