Analytics
2.4K members online now
2.4K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Two tracking codes on one page

Follower ✭ ✭ ☆
# 1
Follower ✭ ✭ ☆

Hi, community!

 

So I am looking to add a second Google Analytics tracking code to a page and I was wondering if this would work:

 

ga('create', 'UA-12345678-6', 'auto');

ga('create', 'UA-123456-4', 'auto');

ga('send', 'pageview');

ga('send', 'pageview');

 

Do I need a unique identifier on the second one at all?

1 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author Scott B
January 2016

Re: Two tracking codes on one page

Top Contributor
# 2
Top Contributor
Hi Scott :-)

Usually the 2nd one would be a named tracker -

ga('create', 'UA-12345678-6', 'auto');
ga('create', 'UA-123456-4', 'auto', 'myTracker');
ga('send', 'pageview');
ga('myTracker.send', 'pageview');
Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Re: Two tracking codes on one page

Follower ✭ ✭ ☆
# 3
Follower ✭ ✭ ☆
Thanks! Does it have to be named? Does naming it affect anything when I go to look in my analytics account or is it more helpful for the back end to trigger the code to that account?

Re: Two tracking codes on one page

Top Contributor
# 4
Top Contributor
Its for the backend more than anything. without it, sometimes the code can get confused and send all the hits to one account only etc etc.
Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Re: Two tracking codes on one page

Follower ✭ ✭ ☆
# 5
Follower ✭ ✭ ☆
Thanks for the help!

Two tracking codes on one page

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Hi Bronwyn,

 

I have set up in the same above format, still hits are reflecting on one account only.

 

Please find the below :

<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-3333653-1', 'auto');
ga('create', 'UA-96937350-1', 'auto', ‘xyz’);
ga('send', 'pageview');
ga(‘xyz.send’, ‘pageview’);
</script>

 

Kindly help me into this.

Re: Two tracking codes on one page

Top Contributor
# 7
Top Contributor

Hi @Ronak D :-)

Is that a copy paste of the code from the site?
If so, there are syntax errors in some of the single quotes 

 

I' m copy/pasting from your given code example and enlarging+marking in red the applicable code for readability, so as to see where the characters are different/incorrect. You can see how the single quotes in red, differ to the single quotes left in black.

 

If you re-edit the code with something like notepad or another plain text editor, it should correct the incorrect red ones.

 

<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-3333653-1', 'auto');
ga('create', 'UA-96937350-1', 'auto', ‘xyz’);
ga('send', 'pageview');
ga(‘xyz.send’, ‘pageview’);
</script>

 

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Two tracking codes on one page

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭

Hello Bronwyn,

 

Yeah, this was the exact issue.

 

Now fixed, thanks for your help.

Two tracking codes on one page

Top Contributor
# 9
Top Contributor

You're welcome :-)

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Two tracking codes on one page

Visitor ✭ ✭ ✭
# 10
Visitor ✭ ✭ ✭

Hi @Bronwyn V - will it work the same way with having two tracking names?

 

ga('create', 'UA-3333653-1', 'auto', 'abc');
ga('create', 'UA-96937350-1', 'auto', ‘xyz’);
ga('abc.send', 'pageview');
ga(‘xyz.send’, ‘pageview’);

 

Or do you need to have one without a tracker name?