Which method is the right way to setup multiple tr

2019-09-10 18:59发布

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!

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-10 19:08

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

查看更多
Evening l夕情丶
3楼-- · 2019-09-10 19:23

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.

查看更多
登录 后发表回答