google analytics - multiple trackers on one page (cookie conflict) google analytics - multiple trackers on one page (cookie conflict) javascript javascript

google analytics - multiple trackers on one page (cookie conflict)


You can install multiple instances of the Google Analytics tracking code on your web pages to send data to multiple properties in your account.https://support.google.com/analytics/answer/1032400?hl=en

Or you can get creative and do the following per Google's instructions. https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#multipletrackers

<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-XXXX-Y', 'auto');  ga('create', 'UA-XXXX-Y', 'auto', {'name': 'newTracker'});  ga('send', 'pageview');  ga('newTracker.send', 'pageview');</script>


Don't have to use different cookie names as Google Analytics happily works with multiple trackers on the same page. See answers for question Google Analytics - Multiple Trackers for Several Accounts?.

Update

It turns out that using multiple trackers is a working method but has some pitfalls. One of those, that is, you cannot apply different user segmentation for each of them. John Henson demonstrates a workaround that coerces GA to use different cookies, may be you should check it.