draj840143 2013-12-10 21:42 采纳率: 100%
浏览 72
已采纳

Google Analytics的多域跟踪

I've looked through the website and i am unable to find an answer.

Basically: I am using Google Analytics to track views and other stuff on my website, but i have 2 domains, both have the same root folder and are identical in name but one ends in ".com" and the other in ".co.uk"

Currently Google Analytics is only tracking the ".com" domain but i was wondering if i could manipulate the code to track from the ".co.uk" domain as well?

Here's the code:

<script type="text/javascript">

  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXXX-X', 'XXXXXXXXXXX.com');
  ga('send', 'pageview');

</script>
  • 写回答

2条回答 默认 最新

  • dougaopu7938 2013-12-11 01:19
    关注

    You could technically just change the create code to:

    ga('create', 'UA-XXXXXXXX-X', 'XXXXXXXXXXX.co.uk');
    

    or

    ga('create', 'UA-XXXXXXXX-X');
    

    to track visitors on the other domain. There are some issues with this solution though. If a visitor visits co.uk site and then goes to .com site, she will be counted twice(two unique visitors).

    You could have co.uk serve pages with iframe from .com page and have the iframe do the tracking but it is kind of hackish and probably not a good idea.

    Also, are the two websites serving different content? if not, you should probably redirect one of the domains to the other for all kinds of reasons (seo, simplicity etc). If they are serving different content and you don't care about the unique visitor count, the solution above will work for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据