Multiple properties in one universal Google Analytics code

╄→гoц情女王★ 提交于 2019-12-04 07:52:00

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');

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!