15

What are the implications of having two tracking codes on 1 site? Both codes will be right under neath one another

e.g.

<script type="text/javascript">// <![CDATA[
var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-account-1']);
  _gaq.push(['_setDomainName', 'mydomain']);
  _gaq.push(['_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>

and

<script type="text/javascript">// <![CDATA[
var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-account-2']);
  _gaq.push(['_setDomainName', 'mydomain']);
  _gaq.push(['_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>

3 Answers 3

12

Google allows Multiple tracking codes on web pages. However, some configs may not be supported.

You can install multiple instances of the Google 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 website, or if you have multiple versions of a website. 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.

Using Multiple Tracking Objects you can combine multiple Google Analytics ID's and accounts, this is useful for multiple site owners overseeing all of parts of the website. This can be done by editing the JavaScript see the example below:

ga('create', 'UA-XXXX-Y', 'auto');
ga('create', 'UA-12345-6', 'auto', 'newTracker');  // New tracker.
1

There will be no implications, but I suggest that instead you create a separate view on one analytics and give access to whomever you need to give, if that is the reason. Also, if tracking is important to you (which looks like it is), I encourage you to use Google Tag Manager in order to add some events, since with this set-up you will get a lot of info, but that info might be misleading. GA (without configuration and events and other stuff) will collect data that might look ... (not true) to you. With GTM you will get more control over your tracking code, you will not mess up your code, you will have less JavaScript on your site, and most importantly you will get more accurate data in your GA account.

0

Locally hosting the analytics.js code is in 99.9% of cases unnecessary, and more hassle than it’s worth in my opinion. Clever developers like to experiment, and some consider it a good idea to locally host the Google Analytics code on their own server for faster delivery, speeding up website rendering in a browser window. Google doesn’t recommend it and either do I.

1
  • I know why you are getting down-voted. Because the question didn't ask about self hosting the gtag, but regardless you are totally right. Stay away from weird, unproven at scale tricks with your google analytics. One of your most valuable assets.
    – 128
    Commented Dec 4 at 0:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.