11

我在 www.example.com 上有一个网站并使用 Google Analytics。我还设置了提供所有静态内容的 static.example.com。

问题是 GA 的默认行为是在“.example.com”上发出 cookie,但我不希望静态内容流量承载 GA cookie 的权重。

我试过pageTracker._setDomainName("none"); 它在 cookie 问题上效果很好,但它完全搞砸了“平均网站停留时间”报告(从 5 分钟平均到 40 分钟,直到我恢复 _setDomainName 调用的那一天)。

知道为什么会发生这种情况,我该如何解决?

4

3 回答 3

8

解决方案是这样做pageTracker._setDomainName("www.example.com"),然后 GA 会将 cookie 发布到“.www.example.com”。这样分析仍然可以正常工作,并且 cookie 不会泄漏到其他静态子域中。

于 2009-08-19T19:19:57.420 回答
5

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.

于 2009-08-17T08:33:50.830 回答
4

对于加载 Google Analytics javascript async(根据 Google 推荐的方式)的任何人,语法如下所示:

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

此行应该在 _trackPageview 之前,因为它正在配置 cookie。您可以在developers.google.com上找到更多信息。

我还建议在(在我的情况下)allinpoker.se 上设置永久重定向到 www.allinpoker.se,因为您只希望在 www 子域上进行跟踪。

于 2012-11-07T08:54:48.357 回答