Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
93 views
in Technique[技术] by (71.8m points)

javascript - gtag set is not attaching data as expected

I'm trying to follow this guide: https://developers.google.com/gtagjs/reference/api#set

It says that you can use gtag('set', {key: value}) to add a set of values to the next gtag calls. However, it doesn't work.

So, this is the setup I used in order to have gtag available on the app:

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('set', 'anonymizeIp', true);
gtag('config', 'my_ga_tracking_id', {
  send_page_view: false,
  custom_map: {
    dimension1: 'a_dimension' 
  }
});

And then this code once the app is loaded:

gtag('set', { a_dimension: 'test' });
gtag('event', 'an_event');

I expected to see the a_dimension attached to the event an_event sent to GA but I can't find it.

What am I missing?

question from:https://stackoverflow.com/questions/65935187/gtag-set-is-not-attaching-data-as-expected

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I solved by using gtag('config') where I needed to set common dimensions instead of gtag('set').

The only think I dislike in this solution is that I need to have those common values always available at that level.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...