Anshar Firman Anshar Firman - 7 months ago 27
Javascript Question

Google analytics using 2 IDs in one website

I have 2 IDs for Google analytics in our website,

I have added them in the footer. like this

<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-56014134-1', 'auto'); ga('send', 'pageview'); </script>

<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-40468267-10', 'auto'); ga('send', 'pageview'); </script>


And the last ID
UA-40468267-10
is mine, but I cannot to see the traffic in my google analytics account, but the first account is showing traffic.

Is it that just one google analytics account can be used for seeing traffic on a website ?
I know it can be used to fitur adding account in google analytics, but I want to know, is that google analytics only use 1 ID for using it ?

Answer

Tracker overwriting

When you set up asynchronouse loader twice time in a page, the second one overwrites the previous one.

Multiple trackers

Instead of doubled script loader use separate configuration for trackers.

It is described here:

https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#multipletrackers

https://support.google.com/analytics/answer/1032400?hl=en

Multiple properties in one universal Google Analytics code

And it looks like:

<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-56014134-1', 'auto'); // Original
    ga('create', 'UA-40468267-10', 'auto', {'name': 'paralel'});  // New tracker

    ga('send', 'pageview');
    ga('paralel.send', 'pageview'); // Use paralel prefix for every paralels tracker commands
</script>