Google Analytics cookie 与静态内容的子域

发布于 2024-08-02 04:49:24 字数 347 浏览 5 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

顾北清歌寒 2024-08-09 04:49:24

解决方案是执行 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.

怕倦 2024-08-09 04:49:24

Google Analytics 将所有会话数据存储在 cookie 中,帮助其“记住”之前的页面浏览量。函数调用 pageTracker._setDomainName(".example.com") 告诉每个站点为主机 example.com(而不是他们自己的子域)存储 cookie,以确保能够来获取彼此的数据。

表单 pageTracker._setDomainName("none ") 仅在您的网站跨越多个不同域名的情况下才需要。

将此方法设置为none
以下两种情况:

* 您想要禁用跨子域的跟踪。
* 您想要跨两个单独的域名设置跟踪。

跨域跟踪需要
_setAllowLinker()的配置
和_link
方法。

为了回答您的问题,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.

Set this method to none in the
following two situations:

* You want to disable tracking across sub-domains.
* You want to set up tracking across two separate domain names.

Cross-domain tracking requires
configuration of the _setAllowLinker()
and _link
methods.

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.

乱世争霸 2024-08-09 04:49:24

对于任何加载 Google Analytics javascript 异步(Google 推荐的方式)的人来说,语法如下所示:

_gaq.push(['_setDomainName', 'www.allinpoker.se']);

此行应该位于 _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:

_gaq.push(['_setDomainName', 'www.allinpoker.se']);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文