Analytics
2.8K members online now
2.8K members online now
Learn how to set up goals and Ecommerce tracking, verify accuracy of attribution traffic sources, and discuss funnel visualization, Multi-Channel Funnels, the Goal Flow Report, and Enhanced Ecommerce
 
Guide Me
star_border
Reply

Two tracking codes on one site

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

So I want to put two tracking codes on my site.

 

Can I just put one after the other like below in my header.php file? Will it cause any problems?

 

<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-XXXXXXXX-1', 'auto');
ga('send', 'pageview');

</script>

 

<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-YYYYYYYY-1', 'auto');
ga('send', 'pageview');

</script>

Re: Two tracking codes on one site

A T
Participant ✭ ✭ ✭
# 2
A T
Participant ✭ ✭ ✭
Hi,

To track data for two separate properties, you need to create two separate trackers, and at least one of them must be a named tracker.
https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers#working_w...

Once done,
You can easily debug on the website with GA debugger:
https://chrome.google.com/webstore/detail/jnkmfdileelhofjcijamephohjechhna

You can check in chrome, console tab with 'Preserve log' turned ON.

Best Regards,
A.T.

'Star' or 'Accept as Solution' if it helped.

Re: Two tracking codes on one site

Follower ✭ ✭ ✭
# 3
Follower ✭ ✭ ✭

Re: Two tracking codes on one site

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
Okay so is the following better?

&lt;script&gt;
(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-XXXXXXX-1', 'auto');
ga('create', 'UA-YYYYYYY-1', 'auto', 'globalTracker');
ga('send', 'pageview');
ga('globalTracker.send', 'pageview');

&lt;/script&gt;

Re: Two tracking codes on one site

A T
Participant ✭ ✭ ✭
# 5
A T
Participant ✭ ✭ ✭
Should work.

Re: Two tracking codes on one site

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭
Awesome thanks!