Google Analytics 使我创建无 Cookie 域的努力化为泡影
我设置子域 static.map.ninux.org 来加载域 map.ninux.org 的静态文件。目标是拥有一个无 cookie 的域。
我查了一下,发现map.ninux.org上的谷歌分析创建了域名为“.map.ninux.org”的cookie,由于某种原因,该cookie对static.map.ninux.org也有效。
我该如何解决这个问题?
PS:这段代码正确吗?
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26436344-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setDomainName', 'map.ninux.org']);
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
这样我仍然可以得到主机“.map.ninux.org”的cookie
I setup the subdomain static.map.ninux.org to load static files for the domain map.ninux.org. The goal was to have a cookieless domain.
I checked and I found out that google analytics on map.ninux.org creates cookies with the domain ".map.ninux.org" that for some reason are valid also for static.map.ninux.org.
How can I solve this issue?
PS: is this code correct?
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26436344-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setDomainName', 'map.ninux.org']);
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
With this I still get the cookies with host ".map.ninux.org"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:
在为map.ninux.org设置cookie时,不能释放static.map.ninux.org cookie,因为static.map.ninux.org将从map.ninux.org继承所有cookie .org(并且您没有任何机会更改此行为)。
您可能想将 cookiefree 域名更改为 static-map.ninux.org。在这种情况下,_setDomainName 的默认设置“auto”将正常工作。
Edit:
You can't make static.map.ninux.org cookie free when setting a cookie for map.ninux.org, because static.map.ninux.org will inherit all cookies from map.ninux.org (and you don't have any chance to change this behaviour).
You may want to change the cookiefree domain name to static-map.ninux.org instead. In this case the default setting of _setDomainName which is 'auto' will work correct.
谷歌跟踪器参数的排序会破坏游戏。将 setDomainName 参数放在 _trackPageview 之前即可工作。
the ordering of google tracker parameters plays the spoilsport. put the setDomainName parameter before _trackPageview and it will work.
促进无 cookie 域的另一种方法是将您的流量推送到 www.map.ninux.org 而不是 map.ninux.org - 这样,static.map.ninux.org 将保持无 cookie。
然后,与之前的响应一样,您可以使用以下指令
或者对于 Google Analytics 的另一种风格,如下所示:
您可以相应地手动修改“ga create”部分:
这将导致 Google Analytics 在 . www.map.ninux.org 域,而不是 .ninux.org 域。
Another way of facilitating cookieless domains is to push your traffic onto www.map.ninux.org rather than map.ninux.org - that way, static.map.ninux.org will remain cookieless.
Then, as in the previous response, you can use the following directive
Or for another flavour of Google Analytics that looks like this:
You can manually modify the "ga create" portion accordingly:
That will cause Google Analytics to create their cookies on the .www.map.ninux.org domain, rather than on .ninux.org domain.