Google Analytics multi tracking account dimension

2019-09-06 10:44发布

问题:

I have two google analytics tracking account.

var ga1 = "UA-XXXXXX-1";
var ga2 = "UA-XXXXXX-2";

I then create the object and send the page view.

ga('create', ga1, 'auto');
ga('send', 'pageview');
ga('create', ga2, 'auto', {'name': 'second'});
ga('second.send', 'pageview');

I then set dimension1 in the object and send the page view again.

ga('set', 'dimension1', 'mytown');
ga('send', 'pageview');
ga('set', 'dimension1', 'mytown', {'name': 'second'});
ga('second.send', 'pageview');

And then I view the result on Google Analytics.

  1. Both ga1 and ga2 account can detect that there's a user active on the site using real time report. (e.g.: current active user = 1)
  2. But, only account ga1 can record that there's a dimension1 value received on the custom report. The custom report for the same dimension on ga2 is empty whatsoever.

Why? Is there someone can point me where my code is wrong? Thanks.

This is the combined code.

var ga1 = "UA-XXXXXX-1";
var ga2 = "UA-XXXXXX-2";

ga('create', ga1, 'auto');
ga('send', 'pageview');
ga('create', ga2, 'auto', {'name': 'second'});
ga('second.send', 'pageview');

ga('set', 'dimension1', 'mytown');
ga('send', 'pageview');
ga('set', 'dimension1', 'mytown', {'name': 'second'});
ga('second.send', 'pageview');

Thanks!

回答1:

I think the problem may be here:

ga('set', 'dimension1', 'mytown', {'name': 'second'});

When you set dimension1, you need to prefix the method with the name of the second tracker, if you are trying to set the dimension for the second tracker.

So it should be

ga('second.set', 'dimension1', 'mytown');