使用 Google Analytics 对子域进行跨域跟踪
我刚刚设置了谷歌分析跨域跟踪。
我已经看到了一些示例,但想确保我已经正确完成了它。
我遵循的文档在这里:http://support.google.com/analytics/bin/static.py?page=guide.cs&guide=1034143&topic=1033979
我基本上有 3 个网站,它们都是子网站- 域。
one.mysite.com
two.mysite.com
three.mysite.com
我已将以下行添加到默认 Analytics 脚本中,并确保对 _setAccount 使用相同的值。
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
现在...我有点困惑的部分是 _setDomainName 变量。
我是否应该在所有三个网站上将其保留为“none”并让 _setAllowLinker 完成工作,或者我是否打算单独指定域,如下所示?
_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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于跨子域流量,您不需要需要设置
_setAllowLinker
,尽管这没有什么坏处。该功能的作用是能够传输您的 Google Analytics cookie 以进行跨域跟踪。该功能由函数_link
启用,对于您的用例来说不是必需的。如果您将
setDomainName
设置为 none,它的作用是将域哈希设置为1
并将 cookie 的域设置为当前域。这无助于您进行跨子域跟踪,因为子域之间的流量将被视为引用。如果您没有要跟踪的第三级子域(例如
foo.bar.example.com
),您所需要做的就是将您的域名设置为域的根目录,如下所示:如果您如果您认为您需要第 3 级子域跟踪,则应该在
mysite.com
前面放置一个前导句点,如下所示:您在这里所做的是两件事。一,您声明 cookie 应设置在哪个域(在本例中,上述 2 个域是相同的)并且您正在配置将使用哪个域来创建“域哈希” ,这是 Google Analytics cookie 中的第一个句点分隔值。 Google Analytics 使用“域哈希”来防止 cookie 冲突;如果您在 setDomainName 中配置的值的域哈希与 ga.js 检测到的 cookie 开头的哈希不一致,它将创建一组新的 cookie 并创建一次全新的访问(就您而言,这不是您想要的。)
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 to1
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:If you think you'll need 3rd level subdomain tracking, you should put a leading period in front of
mysite.com
, like so: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.)