[英]View Google Analytics on another site
Just checking this is correct and I'm not gunna make a hash of my stats.... 只是检查这是正确的,而且我不是将自己的统计数据作为哈希值...。
I have a website, www.mydomain.com and I have signed up to a third party service on www.notmydomain.com/mypage 我有一个网站www.mydomain.com,并且已经在www.notmydomain.com/mypage上注册了第三方服务
I already have Google Analytics set up on www.mydomain.com and would like to view stats from /mypage within the same account. 我已经在www.mydomain.com上设置了Google Analytics(分析),并希望从同一帐户中的/ mypage查看统计信息。
After reading tracking multiple domains I think that I need to add the following code the the HEAD on /mypage 阅读跟踪多个域后,我认为我需要在/ mypage上的HEAD中添加以下代码
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-650003-1']);
_gaq.push(['_setDomainName', 'mydomain.com']);
_gaq.push(['_setAllowLinker', true]);
_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>
This is using the same UA* code as on www.mydomain.com and I'm obviously specifying the same domain here too. 这使用的是与www.mydomain.com上相同的UA *代码,我显然也在此处指定了相同的域。
Questions : 问题 :
1) Is the above the correct way to do this? 1)以上是正确的方法吗?
2) Would I have to change the GA code snippet on mydomain.com to match the one above? 2)我是否必须更改mydomain.com上的GA代码段以匹配上述代码? (It already does everything except _setDomainName and _setAllowLinker ) (除了_setDomainName和_setAllowLinker,它已经可以执行所有操作)
3) Would the same work for subdomains on my own site, eg mysubdomain.mydomain.com 3)对于我自己站点上的子域,例如mysubdomain.mydomain.com,是否可以使用相同的功能
As for 1), I believe that your code is indeed the correct way to do this. 对于1),我相信您的代码确实是执行此操作的正确方法。 I am currently tracking multiple subdomains using this method. 我目前正在使用此方法跟踪多个子域。
If you want 3), you need to do 2). 如果需要3),则需要执行2)。
Re 3, the following is sufficient for tracking across multiple subdomains: 在第3版中,以下内容足以跨多个子域进行跟踪:
_gaq.push(['_setDomainName', 'mydomain.com']);
However, strictly speaking you should add a leading period to the domain name, like this: 但是,严格来说,您应该在域名前添加前置符,例如:
_gaq.push(['_setDomainName', '.mydomain.com']);
It should still work without it but this should ensure better cross-browser compliance. 没有它,它仍然可以工作,但是这可以确保更好的跨浏览器兼容性。
The line: 该行:
_gaq.push(['_setAllowLinker', true]);
is only required for cross-domain tracking. 仅需要跨域跟踪。 It also needs to appear on www.notmydomain.com/mypage. 它也需要出现在www.notmydomain.com/mypage上。
Don't forget you also need to add a linker function to all the links from mydomain.com to notmydomain.com (and vice-versa if you think visitors might start their visit from notmydomain.com). 别忘了,您还需要在mydomain.com到notmydomain.com的所有链接中添加链接器功能(如果您认为访问者可能从notmydomain.com开始访问,则反之亦然)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.