javascript - Google analytics analytics.js 2 two trackers colliding? -
i using analytics.js script track 3 sites - 2 2nd level domains , 1 subdomain... example: dom1.com, sub.dom1.com, dom2.com
the script , site have trouble dom1.com in example. have 2 properties should aggregate following data:
property : dom1.com + sub.dom1.com property b : dom1.com + sub.dom1.com + dom2.com
i have been looking bug in code can't figure out problem, is:
in property aggregated correctly , both domain , subdomain sending data fine. in property b sub.dom1.com , dom2.com send data dom1.com not.
this script in header of dom1.com:
ga('create', 'propertya', 'auto', {'name': 'trackera'}, {'allowlinker': true}); ga('trackera.send', 'pageview'); ga('require', 'linker'); ga('linker:autolink', ['sub.dom1.com', 'dom1.com']); ga('create', 'propertyb', 'auto', {'name': 'trackerb'}, {'allowlinker': true}); ga('trackerb.send', 'pageview'); ga('require', 'linker'); ga('linker:autolink', ['sub.dom1.com', 'dom1.com', 'dom2.com']);
i have tried moving second tracker above in case script not run, didn't solve anything. figure problem somewhere in way try use linker 2 times, maybe wrong?
thank help, hope helps else too.
there couple things wrong implementation (not of these contributing problem, still best-practices):
in general, should require plugins , invoke plugin initialization before doing else tracker since many plugins alter behavior and/or data stored on tracker(s).
you not need specify subdomains in
autolink
method, tracked automatically since you're usingauto
enable automatic cookie domain configuration.you cannot pass 2 objects
create
method, instead should combine options single object or use shorthand (e.g.ga('create', trackingid, cookiedomain, trackername, additionalconfigoptions);
when using multiple trackers, must specify tracker name when requiring plugins , invoking plugins methods (e.g.
ga('trackername.require', 'pluginname');
,ga('trackername.pluginname:methodname', methodoptions);
)
if update code follows, should work:
ga('create', 'propertya', 'auto', 'trackera', {'allowlinker': true}); ga('trackera.require', 'linker'); ga('trackera.linker:autolink', ['dom1.com']); ga('trackera.send', 'pageview'); ga('create', 'propertyb', 'auto', 'trackerb', {'allowlinker': true}); ga('trackerb.require', 'linker'); ga('trackerb.linker:autolink', ['dom1.com', 'dom2.com']); ga('trackerb.send', 'pageview');
Comments
Post a Comment