Which method is the right way to setup multiple trackers in Google (Universal) Analytics?

时间秒杀一切 提交于 2019-12-13 05:32:38

问题


I'm setting up multiple trackers to track 2 properties I setup in my Google Analytics. I found this link from Google which I use to set this up as the following:

https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers#working_with_multiple_trackers

ga('create', 'UA-XXXXXXX-6', 'auto');
ga('send', 'pageview');
ga('create', 'UA-XXXXXXX-8', 'auto', 'clientTracker');
ga('clientTracker.send', 'pageview');

However, when I search online I see people responding with the following:

ga('create', 'UA-XXXXXXX-6', 'auto');
ga('send', 'pageview');
ga('create', 'UA-XXXXXXX-8', 'auto', {'name': 'clientTracker'});
ga('clientTracker.send', 'pageview');

Should I be using just 'clientTracker' or {'name': 'clientTracker'} in my Universal tracking code?

Thank you!


回答1:


Both are valid and do the same thing. The documentation indicates the ga() function's signature is:

ga(command, [...fields], [fieldsObject])

and https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#method-details indicates the create operation's fields are:

ga('create', [trackingId], [cookieDomain], [name], [fieldsObject]);

The docs also note that:

If a field is set in both a fields parameter and fieldsObject, the value in fieldsObject will be used.

so either way is valid, and the second way will override the first.




回答2:


Use the below code because it's descriptive:- {'name': 'clientTracker'}



来源:https://stackoverflow.com/questions/35761700/which-method-is-the-right-way-to-setup-multiple-trackers-in-google-universal-a

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