问题
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 andfieldsObject
, the value infieldsObject
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