Google Analytics cookie 与静态内容的子域
我在 www.example.com 上有一个网站并使用 Google Analytics。我还设置了 static.example.com 来提供所有静态内容。
问题是 GA 的默认行为是在“.example.com”上发布 cookie,但我不希望静态内容流量承载 GA cookie 的重量。
我尝试了 pageTracker._setDomainName("none");,它对于 cookies 问题效果很好,但它完全搞乱了“平均网站停留时间”报告(从平均 5 分钟变成了 40 分钟)直到我恢复 _setDomainName 调用的那一天)。
知道为什么会发生这种情况以及如何解决它吗?
I have a website on www.example.com and use Google Analytics. I've also set up static.example.com which serves all static content.
The problem is that the default behavior of GA is to issue cookies on ".example.com" but I don't want the static content traffic to be carrying the weight the GA cookies.
I tried pageTracker._setDomainName("none"); and it worked well for the cookies problem but it completely messed up the "Avg. Time on Site" report (from 5 mins average it went to 40 mins until the day I reverted the _setDomainName call).
Any idea why this is happening and how could I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案是执行
pageTracker._setDomainName("www.example.com")
,然后 GA 会将 cookie 发布到“.www.example.com”。这样,分析仍然可以正常工作,并且 cookie 不会泄漏到其他静态子域中。The solution is to do
pageTracker._setDomainName("www.example.com")
and then GA will issue the cookies to ".www.example.com". That way analytics still works fine and the cookies do not leak into the other static subdomain.Google Analytics 将所有会话数据存储在 cookie 中,帮助其“记住”之前的页面浏览量。函数调用
pageTracker._setDomainName(".example.com")
告诉每个站点为主机 example.com(而不是他们自己的子域)存储 cookie,以确保能够来获取彼此的数据。表单
pageTracker._setDomainName("none ")
仅在您的网站跨越多个不同域名的情况下才需要。为了回答您的问题,Google Analytics 使用基于第一方的 cookie 来收集数据。当您希望静态内容的流量出现在 GA 中时,您也必须允许它们使用 cookie。为了避免此问题,您可以选择解析服务器日志的服务器解决方案,例如 Urchin文件而不是处理 cookie。
Google Analytics stores all session data in cookies that helps it to ‘remember’ previous page views. The function call
pageTracker._setDomainName(".example.com")
tells every sites to store cookies for host example.com (instead of their own subdomain) to ensure the ability to reach each other's data.The form
pageTracker._setDomainName("none")
is needed in and only in that case when your site spans across multiple, different domain names.To answer your question, Google Analytics uses first-party based cookies for collecting data. When you want your static content's traffic to appear in GA, you have to allow cookies for them, too. To avoid this issue, you may choose a server solution like Urchin that parses server log files instead of dealing with cookies.
对于任何加载 Google Analytics javascript 异步(Google 推荐的方式)的人来说,语法如下所示:
此行应该位于 _trackPageview 之前,因为它正在配置 cookie。您可以在 developers.google.com 上找到更多信息。
我还建议在(就我而言)allinpoker.se 上设置永久重定向到 www.allinpoker.se,因为您只需要在 www 子域上进行跟踪。
For anyone loading the Google Analytics javascript async (the recommended way according to Google) the syntax looks like this:
This line should be before _trackPageview since it's configuring the cookies. You could find more info on developers.google.com.
I also recommend setting up a permanent redirect on (in my case) allinpoker.se to www.allinpoker.se since you only want the tracking on the www sub domain.