Google Analytics cookies vs subdomain for static content

社会主义新天地 提交于 2019-11-30 12:41:39

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 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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!