Blog

Home > Analytics FAQs > How to Add Multiple Google Analytics Tracking Codes

How to Add Multiple Google Analytics Tracking Codes

You can add multiple google analytics tracking codes to the same page. In order to make sure that both are unique and track their respective events you just need to make little modifications to your code. Your primary code will look like this:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX">
</script> 

<script> 
      window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-XXXXXXX'); </script>

It is a standard code provided by Google. In order to add additional code to your site you need to add tracker name to your code. For that,  you will need to modify last few lines of your code.

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script> 
<script> 
     window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); 
     gtag('config', 'G-XXXXXXX');
     gtag('config', 'G-YYYYYYY', 
     { 'send_page_view': true, 'cookie_prefix': 'myTracker' }); 
</script>

Code should be added with in all Google Analytics tracking codes on site. For example, for event tracking our code will be as follows:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script> 

<script> 
       window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-XXXXXXX');
       gtag('config', 'G-YYYYYYY');
       gtag('event', 'play', { 'page_title': '{{Page Title}}', 'page_path': '{{Page Path}}', 'send_to': 'G-XXXXXXX' });       
       gtag('event', 'play', { 'page_title': '{{Page Title}}', 'page_path': '{{Page Path}}', 'send_to': 'G-YYYYYYY' }); 
</script>

Note: Adding tracker name may result in loss of tracking from plugins present on site that automatically sends data to your GA account by locating code on site. For example, Justuno marketing plugin sends data directly to GA by locating GA code on site and then pushing event code within it. However, it fails if you have modified your tracker name.

If this isn’t helpful click here to read more. Adding multiple tracking codes with tag manager is more easier than this method.

Share:

Hussain

Analytics Strategy Pioneer

C-Suite Whisperer 14 Years Industry Vet

Case Studies

Discover our latest success stories and see how innovative strategies drive measurable results.

Are you Ready to Fast Track your Marketing Attribution Decisions and Maximize your ROI?

Businesses that leverage automated marketing
attribution see a 20-30% improvement in ad
spend efficiency.