Name Spaced Accounts Not working Under Universal Analytics

点点圈 提交于 2019-12-11 20:13:53

问题


I would like to migrate to universal analytics.js, however when I try to implement multiple accounts in the analytics.js snippet, the default account works great and shows up in Real Time, however the subsequent account never shows up on Real Time and traffic drops off to 0.

Currently I'm using ga.js to track multiple accounts in the single snippet. Here is the format I am using for that:

    <script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(
            ['_setAccount', 'UA-XXXXXXXX-2X'],
            ['_setDomainName', 'example.com'],
            ['_addIgnoredRef', 'example.com'],
            ['_trackPageview'],
            ['b._setAccount', 'UA-YYYYYYYY-2Y'],
            ['b._setDomainName', 'example.com'],
            ['b._addIgnoredRef', 'example.com'],
            ['b._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>

Below is the snippet I have been trying to make work with analytics.js

    <script>
      (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-2X', 'example.com');
      ga('send', 'pageview');
      ga('create', 'UA-YYYYYYYY-2Y', {'name': 'rollup'});
      ga('rollup.send', 'pageview');

    </script>

The "rollup" name space never registers on the rollup account in real time. The UA-XXXXXXXX-2X code registers just fine in Real Time.

I have run Google Analytics Debugger and it appears to be creating both accounts and sending just fine with no errors only info that looks appropriate:

Running command: ga(create, UA-YYYYYYYY-2Y, [object Object])
Creating new tracker: rollup
Running command: ga(rollup.send, pageview)

Could anyone offer some guidance on what might be the problem with my analytics.js snippet?


回答1:


Here is the Google Universal Analytics Code that merges two Profiles and even sends demographic data.

Just replace - UA-XXXXXX-Y with UA-XXXXXX-X with your GA tracking IDs. and replace EXAMPLE.com with the website domain and all set to go.

FYI - OldSite - you can replace it with whatever you like - its just used separate profile for the GA to send captured data. so you can use SecondProfile, IloveCodes or whatever.

This script additionally sends demographics and other data - how cool is that?

Enjoy!

And Yes thanks to all the guys out there who helped me reaching out to this answer.

<script>
  (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-XXXXXX-Y', 'EXAMPLE.com');
  ga('create', 'UA-XXXXX-X', {'name':'Oldsite'});
  ga('send', 'displayfeatures');
  ga('Oldsite.send', 'displayfeatures');
  ga('send', 'pageview');
  ga('Oldsite.send', 'pageview');
</script>



回答2:


If you are also experiencing this, ensure that all the accounts you are attempting to track have already been upgraded to Universal Analytics via the GA Admin menu. A face palm moment for me, but perhaps this reminder will help anyone else who may be experiencing the same issue.



来源:https://stackoverflow.com/questions/23749392/name-spaced-accounts-not-working-under-universal-analytics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!