Apply 2 Google Analytics tracking Ids

Asked

Viewed 139 times

0

I need to apply 2 Google Analytics tracking Ids to a website. I already generated the first ID. I was reading, that if I just put one above the other, it won’t work. What to do?

<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','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-00000000-00', 'auto');
  ga('send', 'pageview');

</script>
  • 1

    The two Ids will be for the same pages?

  • 1

    I’ve already put both and sure yes

  • @LINQ yes, will monitor the same site and the same pages.

  • @Karlzillner impacts negatively on the final result.

  • 1

    And what’s the point of having two Ids?

  • @LINQ two separate accounts will manage the same account.

Show 1 more comment

1 answer

3


According to himself google support you can use normally, only nay should repeat the file instance ga js., this can cause conflicts. You can also name each ID and use it this way:

<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','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-00000000-0', 'auto');
ga('create', 'UA-00000000-1', 'auto', 'xyz');
ga('send', 'pageview');
ga('xyz.send', 'pageview');
</script>

Note that the Xyz is the name assigned to the instance of the second ID, so it uses the function send differently on the second call.

  • I just edited some quotes were wrong, the code was wrong. Now it’s fixed.

  • 1

    It worked that way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.