Multiple properties in one universal Google Analyt

2019-04-09 07:16发布

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.

2条回答
Emotional °昔
2楼-- · 2019-04-09 07:52

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');
查看更多
狗以群分
3楼-- · 2019-04-09 08:06

I don't know if this helps, but I had been running into a wall for a solid two hours with the Universal Analytics and my named tracking object. Here's a code example for clarification that I had a hard time finding:

ga('create', 'UA-12345678-1', {
    'cookieDomain': 'example.com',
    'legacyCookieDomain': 'example.com',
    'allowLinker': false}
);
ga('send', 'pageview');
ga('set', 'location', '/path/to/object/');

ga('create', 'UA-12345678-2', {
    'cookieDomain': 'example.com',
    'legacyCookieDomain': 'example.com',
    'allowLinker': false,
    'name': 'exampledomain'}
);
ga('exampledomain.send', 'pageview');
ga('exampledomain.set', 'location', '/path/to/object/');

Spaces had absolutely NOTHING to do with it. The problem I was running into was that I had a hyphen in my 'exampledomain' and it didn't work. Do not trust any odd characters in the string for the 'name' of any other tracking object!

Also, notice the 'name' key should be inside the opt_configObject. I say this because I found that documentation nowhere.

查看更多
登录 后发表回答