Adding multiple google analytics properties to a website

Adding multiple google analytics properties to a website, if you want to add multiple google analytics tracking codes here is simple code for doing this. By using this code you can add any number of google analytics properties. Here in this below code you can add upto two google analytics accounts, if you want to add extra google analytics accounts repeat the code and replace the tracking code of your google analytics account.

Code for Adding multiple google analytics properties to a website

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
  _gaq.push(['_trackPageview']);

  // Second tracker 
  _gaq.push(['secondTracker._setAccount','UA-YYYYYYYY-Y']); 
  _gaq.push(['secondTracker._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>

If you want to add extra trackers just use this code after second tracker.

// Third tracker 
  _gaq.push(['thirdTracker._setAccount','UA-YYYYYYYY-Y']); 
  _gaq.push(['thirdTracker._trackPageview']);

For more information about How to link multiple Google Analytics accounts to your website

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe