谷歌分析和静态子域
首先:它与 类似,但没有 www 前缀问题。
我有一个网站 example.com(再次强调,没有“www.”前缀)。我想提供来自子域 static.example.com 的静态内容,但 Google Analytics 继续从静态子域发送 cookie。
我使用简单的 CNAME 来创建子域,这是 Analytics 代码段:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXX-XX']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_trackPageview']);
(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);
})();
</script>
我尝试将 _setDomainName
设置为 example.com
和 none
如上所述,但是它不起作用。我还每次都创建了一个新的静态子域(static2.example.com 等),但它也不起作用。
提前致谢。
First of all: it's not the same as similiar, but without www prefix problem.
I have a website example.com (once again, no "www." prefix). I'd like to serve static content from subdomain static.example.com but Google Analytics keeps to send cookies from static subdomain.
I used a simple CNAME to make subdomain, and here's the Analytics snippet code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXX-XX']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_trackPageview']);
(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);
})();
</script>
I tried setting _setDomainName
to example.com
and none
as above but it doesn't work. I also made a new static subdomain (static2.example.com etc) on each time but it didn't work also.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想让您的静态子域免受 GA cookie 的影响,您应该告诉 GA 不要在您网站的根域上设置 cookie。如果您使用 www 子域并将 DomainName 设置为该子域,它应该可以正常工作。由于您无法做到这一点,因此为 example.com(无 www)设置 cookie 会将该 cookie 分配给主域,并且它们将被转发到任何子域。
适合您的解决方案是:
为您的内容使用子域。 (www 或其他任何内容),并在 _setDomainName 上设置完整域
为您的静态内容注册一个新的根域。类似 staticexample.com
If you want to keep your static subdomain free from GA cookies you should tell GA not to set cookies on the root domain for your site. If you used the www subdomain and set DomainName to that one it should work fine. Since you can't manage to do that, setting cookies for example.com (no www) will assign that cookie to the master domain and they'll be forwarded to any subdomain.
The solutions for you are:
Use a subdomain for your content. (www or anything else), and set that full domain on _setDomainName
Register a new root domain for your static content. Something like staticexample.com