子域跟踪相关跟踪代码修改后,谷歌分析返回访客数量下降
上周五,我们将网站 www.ourweb.com 跟踪从“单域”更改为“一个域到多个子域”,以跟踪 www.ourweb.com 和 blog.ourweb.com 所以我修改了网站上的代码:(
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-1594022-3");
pageTracker._trackPageview();
</script>
注意我们之前使用了传统的代码片段):
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', '.ourweb.com']);
_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);
})();
但在过去的几天里,网站报告回访者几乎翻了一番!从稳定的 7 000 人下降到 4 000 人,
只有回访者数量变化很大,新访客数量保持相似(大约 10 000 人)
我读了这篇文章 http://www.roirevolution.com/blog/2011/01/google_analytics_subdomain_tracking.php
他们在那里写道“前导句点导致 cookie 重置。”。这就是游客大幅下降的原因吗?我应该删除前导句点吗?如果不是,还有什么原因呢?
附:我刚刚注意到这可能只是推荐的问题。变更后,来自推荐的访客量从每天 4000 人减少到 700 人左右。
last friday we switched our website, www.ourweb.com tracking from "single domain" to "one domain to multiple sub-domains", to track both www.ourweb.com and blog.ourweb.com
so i modified the code on the site:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-1594022-3");
pageTracker._trackPageview();
</script>
to (note we used traditional snippet before):
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', '.ourweb.com']);
_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);
})();
but over last few days, site reported almost double returning visitors drop! from stable 7 000 down to 4 000
only returning visitors number changed that much, new visitors number keeps being similar (around 10 000)
i read this http://www.roirevolution.com/blog/2011/01/google_analytics_subdomain_tracking.php
and they write there that "The leading period causes cookie resets.". is that the reason of such big visitors drop? should i remove the leading period? and if not, what else could be the reason?
ps. i just noticed that probably it's referrals only problem. amount of visitors from referrals decreased from 4000 to around 700 per day after change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 Google Analytics 的一个愚蠢的怪癖,应该更好地记录下来。
有 2 种同样有效但略有不同的方法来使用
_setDomainName
。无引导期:
引导期:
Google Analytics 使用所谓的“域哈希”(字面意思是域的哈希值或您在
_setDomainName
中设置的域的哈希值)来防止 Cookie 之间发生冲突;如果您配置的域的域哈希与它找到的 Google Analytics cookie 不匹配,它会创建一个全新的访问(以及一个全新的访问者)。区别在于:默认情况下,如果您未配置
setDomainName
,您的根www
域将获得一个“域哈希”,该哈希值与http://ourweb.com。这可能是为了防止 www.并且没有www。但是,如果添加前导句点,“域哈希”就会发生变化。您的回访者都不会拥有匹配的域哈希。因此,当他们进入您的网站时,Google Analytics 不会看到一组具有正确域哈希的匹配 cookie,并会创建一个新的访客 ID,并且自更改以来的所有流量都与更改前的流量完全隔绝。
因此,如果您在不使用
_setDomainName
的情况下进行了长期跟踪,并且希望添加对跨子域跟踪的支持,则对最后一次损坏执行此操作的方法是不使用前导句点。您可以通过切换到不使用前导句点来“恢复”旧的 cookie。但如果您这样做,您将丢失 cookie,因为您已经进行了更改。
使用前导句点的唯一好处是它提供了对第三级子域(即
foo.bar.example.com
)的兼容性。This is a silly quirk of Google Analytics that should be better documented.
There are 2 equally valid but slightly sifferent methods for using
_setDomainName
.No Leading Period:
Leading Period:
Google Analytics uses something called a "domain hash" (literally, a hash of the domain or of the domain you set in
_setDomainName
) to prevent conflicts between cookies; if the domain hash of the domain you've configured does not match the Google Analytics cookies that it finds, it creates a brand new visit (and a brand new visitor).The difference is this: By default, if you don't configure your
setDomainName
, your rootwww
domain gets a "domain hash" that is the same as if it is just http://ourweb.com. That's presumably to prevent self-referrals for traffic between www. and no www.However, if you add the leading period, the "domain hash" changes. None of your returning visitors will have a matching domain hash. So, when they enter your site, Google Analytics doesn't see a matching set of cookies with the correct domain hash and creates a new visitor id, and all your traffic since the change is totally cut off from the traffic before the change.
As a result, if you have long-standing tracking without using
_setDomainName
, and you'd like to add support for tracking across subdomains, the way to do so with the last damage is to use no leading period.You can "recover" the old cookies by switching to using no leading period. If you do so, you'll lose the cookies since you've made the change, though.
The only benefit in using the leading period is that it provides compatibility for third level subdomains (ie,
foo.bar.example.com
).访客下降的原因是 ourweb.com 和 www.ourweb.com 之间没有直接重定向
ourweb.com 显示与 www.ourweb.com 相同的网站,但所有链接都指向 www.ourweb.com,并且所有 3000 次回访下降来自自我推荐。
因此,cookie 被分割在这两个网站之间,并创建虚假的唯一回访(每次访问者访问 ourweb.com 并单击指向 about.html 的 f.ex. 链接时,他都会访问 www.ourweb.com/about.html,所以 ga将其视为两次独立的唯一回访),
因此以前的报告基本上是错误的,并且变得更加准确。
visitors drop happened because there was no straight redirect between ourweb.com and www.ourweb.com
ourweb.com was displaying same site as www.ourweb.com, but with all links pointing to www.ourweb.com, and all 3000 return visits drop came from self referrals.
thus cookies were split between those two sites and created fake unique return visits (each time visitor visited ourweb.com and clicked f.ex. link to about.html, he was going to www.ourweb.com/about.html, so ga counted it as two independent unique return visits)
so basically reporting was wrong before and became more accurate.