I am setting up a Custom Dimension in my Google Analytics Tracking Code, however I am seeing a strange error in the Chrome Console with the Google Analytics Debugger switched on.
This is my code which is fired on every page. I am reporting to a regional account as well as a global/rollup account and I have created two trackers to achieve this.
<script>
(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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-85521872-1', 'auto', 'crmpiccoglobal');
ga('create', 'UA-85521872-3', 'auto', 'crmpiccoregion');
ga('set', 'dimension1', 'premium');
ga('crmpiccoglobal.send', 'pageview');
ga('crmpiccoregion.send', 'pageview');
</script>
In the console I see this:
Running command: ga("set", "dimension1", "premium")
analytics_debug.js:10 Command ignored. Unknown target: undefined
I have created the Custom Dimension in GA under each property I want to access it in.
You need to use your tracker names in the "set" command, else GA will apply the command to the default tracker t0 (which does not exist in your example):
ga('crmpiccoglobal.set', 'dimension1', 'premium');
ga('crmpiccoregion.set', 'dimension1', 'premium');
ga('crmpiccoglobal.send', 'pageview');
ga('crmpiccoregion.send', 'pageview');
If you use Google Tag Manager to load your Google Analytics and you don't know what tracker is being created, use this:
sendGa(name : string, data: any) {
(<any>window).ga(() => {
var trackers = (<any>window).ga.getAll();
var firstTracker = trackers[0];
var trackerName = firstTracker.a.data.values[":name"];
(<any>window).ga(trackerName + '.' + name, data);
});
}
docs: https://developers.google.com/analytics/devguides/collection/analyticsjs/accessing-trackers
I would recommend to use the debug version of the analytics.js library analytics_debug.js and you will see the causes of the bugs in the console
来源:https://stackoverflow.com/questions/39990601/command-ignored-unknown-target-undefined-when-setting-custom-dimension-in-goog