Pages Navigation Menu

Use multiple Google Analytics trackers on one page

1. In the same block of code

Plugins “linkid” and “displayfeatures” in below code are as example only. You can remove that lines from your code.

// tracker named 'FOO' for property UA-XXXXX-X
	ga('create', 'UA-XXXXX-X', {name: 'FOO'});
	ga('FOO.require', 'linkid');
	ga('FOO.require', 'displayfeatures');
	ga('FOO.send', 'pageview');

// second tracker named 'BAR' for a UA-YYYYY-Y
	ga('create', 'UA-YYYYY-Y', {name: 'BAR'});
	ga('BAR.require', 'linkid');
	ga('BAR.require', 'displayfeatures');
	ga('BAR.send', 'pageview');

2. In separate blocks of JS

<script type="text/javascript">
(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-000000-0', 'auto');
	ga('send', 'pageview');
</script>

and

(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-000000-0',{'name':'prop2'});
	ga('prop2.send','pageview');

Leave a Reply