Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple properties in one universal Google Analytics code

I am trying to embed a GA code in my website that is based on the new Universal Analytics method. What I am trying to achieve is to send data to multiple properties from one page.

So I have checked the official GA documentation on the new universal GA code and specifically the section about "Working with multiple tracking objects".

https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#multipletrackers

But so far without success.

I have one domain for the standard website www.website.de and another one for the mobile website de.website.mobi.

My GA code for my standard website looks like this:

(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-12345678-1');
ga('create', 'UA-12345678-2', {'name': 'newTracker'});
ga('send', 'pageview');
ga('newTracker.send', 'pageview');

In the GA real time section I can see that the property UA-12345678-1 is getting real time results but the the second property isn't getting results at all.

Does anybody know the reason? Am I mistunderstanding the GA documenation.

To clarify: On my mobile website I would like to embed the following code:

(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-12345678-1');
ga('create', 'UA-12345678-3', {'name': 'newTracker'});
ga('send', 'pageview');
ga('newTracker.send', 'pageview');

So, I have three properties: UA-12345678-2 for the standard website, UA-12345678-3 for the mobile website and UA-12345678-1 as an aggregation of both giving me the opportunity to see the results of standard website and mobile website summed up. At least that is what I am trying to achieve.

Any ideas are welcome.

like image 849
humboldt12 Avatar asked Nov 01 '22 15:11

humboldt12


1 Answers

What you have should work. I went and tested this myself, and sure enough, it didn't work. Next, I tried removing the spaces between the objects, as I've seen in the past that this has cause the code to not show up in GA. I'm not sure why, but by removing the spaces from all of the parameters and objects, I was able to get data to show up in real-time reports.

I tried adding the spaces back to the parameters and objects, but was unable to get the data to NOT show up again. Regardless of what I did, data kept coming through.

I would try this:

(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-12345678-1');
ga('create','UA-12345678-3',{'name':'newTracker'});
ga('send','pageview');
ga('newTracker.send','pageview');
like image 111
Blexy Avatar answered Nov 08 '22 09:11

Blexy