Analytics
2.5K members online now
2.5K 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

Tracking events with multiple UA numers on same page - Universal Analytics

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello, Im using Universal Analytics with 3 UA numbers on same page ( 1 for all platforms , 1 for desktop and 1 for mobile),
and I'm using an event tracking for clicks and impressions of a banner ( ga(send ...) ). But I'm not able to control wich UA number will receive the report. How can i do that?

 

Thanks.

 

Hugo Deveza

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Smoke B
April 2016

Re: Tracking events with multiple UA numers on same page - Universal Analytics

Follower ✭ ✭ ☆
# 4
Follower ✭ ✭ ☆

I have created a jsbin for an example right here!

 

https://jsbin.com/kelupatuqu/1/edit?html,console,output

 

the code is roughly as it shows below.

 

 

 

 

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<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', {
trackingId: 'UA-30589012-4',
cookieDomain: 'auto',
name: 'myTracker1',
});

ga('create', {
trackingId: 'UA-30589012-1',
cookieDomain: 'auto',
name: 'myTracker2',
});


ga('send', 'pageview');

</script>
</head>
<body>

<a onClick="ga('myTracker1.send', 'event', 'bannercat', 'click', 'bannername');">Event1</a>
<br>
<br> <br>

<img width="100" src="//i.imgur.com/7cASRSW.jpg" alt="..." onload="ga('myTracker2.send', 'event', 'banner', 'impression','bannername',2.00, {'nonInteraction': 1});">
</body>
</html>

View solution in original post

Re: Tracking events with multiple UA numers on same page - Universal Analytics

Follower ✭ ✭ ☆
# 2
Follower ✭ ✭ ☆
It sounds like you will need to employ named trackers like the below:

Running commands for a specific trackers

To run analytics.js commands for a specific tracker, you prefix the command name with the tracker name, followed by a dot. When you don't specify a tracker name, the command is run on the default tracker.

To send pageviews for the above two trackers, you'd run the following two commands:

ga('send', 'pageview'); //default
ga('clientTracker.send', 'pageview'); //named tracker

You can see the full article here!


Re: Tracking events with multiple UA numers on same page - Universal Analytics

[ Edited ]
Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Ok, thats how i send a pageview, but what If I need to send an event like a click or an impression of a banner?

This?

<a onClick="ga('myUAname.send', 'event', 'bannercat', 'click', 'bannername');">...</a>

 

 

This?

<img src="..." alt="..." onload="ga('myUAname.send', 'event', 'banner', 'impression','bannername',2.00, {'nonInteraction': 1});">

Marked as Best Answer.
Solution
Accepted by topic author Smoke B
April 2016

Re: Tracking events with multiple UA numers on same page - Universal Analytics

Follower ✭ ✭ ☆
# 4
Follower ✭ ✭ ☆

I have created a jsbin for an example right here!

 

https://jsbin.com/kelupatuqu/1/edit?html,console,output

 

the code is roughly as it shows below.

 

 

 

 

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<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', {
trackingId: 'UA-30589012-4',
cookieDomain: 'auto',
name: 'myTracker1',
});

ga('create', {
trackingId: 'UA-30589012-1',
cookieDomain: 'auto',
name: 'myTracker2',
});


ga('send', 'pageview');

</script>
</head>
<body>

<a onClick="ga('myTracker1.send', 'event', 'bannercat', 'click', 'bannername');">Event1</a>
<br>
<br> <br>

<img width="100" src="//i.imgur.com/7cASRSW.jpg" alt="..." onload="ga('myTracker2.send', 'event', 'banner', 'impression','bannername',2.00, {'nonInteraction': 1});">
</body>
</html>

Re: Tracking events with multiple UA numers on same page - Universal Analytics

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
That's It, thank you very much Jason!