JLR
JLR

Reputation: 733

Dual Google analytic codes from two different accounts?

I would like to have dual Google Analytics tracings sent to two different Google Analytics accounts from the same webpage.

I have this Analytics-code today (the standard one):

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

I would like to add tracking to one more account. Can I just add one more "UA-XXXXXXXX-X" to the existing one?

Like so:

<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-12345678-9', 'auto');
      ga('create', 'UA-87654321-0', 'auto');
      ga('send', 'pageview');   
</script>

Would this work properly?

Kind regards Johan Linnarsson

Upvotes: 2

Views: 149

Answers (2)

The code you’re looking for is right here. You’ll need two ga(create) functions and two ga(send) functions. The second of each is slightly different than the first.

// Standard code. Replace X's and domain with your own
ga('create', 'UA-XXXXXXXX-X', 'domain.com');

// Replace Y's with your account number. "b" can be anything you want.
ga('create', 'UA-YYYYYYYY-Y', {'name':'b'});

// Standard code. No change necessary.
ga('send', 'pageview');

// "b" can again be anything you want, but it MUST match "b" above.
ga('b.send', 'pageview');

Add this code to your Google Analytics tracking code tags. You’ll already have the standard create/send lines, provided by Google. Replace them with the example above and remember to replace all those X’s and Y’s with your proper Google Analytics UA tracking code numbers.

Kindly refer below links for additional information

  1. Multiple tracking codes on web pages
  2. Ok, but what does it mean? Multiple Google Analytics tracking objects.
  3. Implications

Upvotes: 1

Nitin Dhomse
Nitin Dhomse

Reputation: 2612

You can install multiple instances of the Analytics tracking code on your web pages to send data to multiple properties in your account.

Not all configurations are supported. You can, for example, install multiple instances of the Universal Analytics tracking code (analytics.js) on your web pages but only one instance of the Classic Analytics code (ga.js). Multiple instances of ga.js might result in inaccurate data collection, processing, or reporting. You can, however, install one or more instances of analytics.js on web pages that also have a single instance of ga.js.

Using multiple tracking codes might be useful if users with access to different properties need to see data from the same web site, or if you have multiple versions of a web site. You might, for example, want to collect data from example.com using one instance of analytics.js, collect data from example.co.uk in another instance of analytics.js, and use a third instance of analytics.js on both websites to see the aggregate data.

Reference

Upvotes: 0

Related Questions