I'm trying to follow this guide:
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?
I'm trying to follow this guide: https://developers.google./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?
Share Improve this question asked Jan 28, 2021 at 10:24 WilkWilk 8,14310 gold badges47 silver badges71 bronze badges 4- 1 have you set this variable in Tag manager itself? – Chris Townsend Commented Jan 28, 2021 at 10:42
- No. Is that required? – Wilk Commented Jan 28, 2021 at 11:43
- So as far as I know yes. I recently did some Gtag stuff and to get it to pass into GA, I had to create the variable, and pass it in to an event trigger – Chris Townsend Commented Jan 28, 2021 at 12:14
- Actually, I defined a dimension, not a tag, on GA. Does it count? – Wilk Commented Jan 28, 2021 at 14:33
3 Answers
Reset to default 3I solved by using gtag('config')
where I needed to set mon dimensions instead of gtag('set')
.
The only think I dislike in this solution is that I need to have those mon values always available at that level.
In short: don't use set. It's meant for GTM. gtag documentation is misleading in this regard. We went more thoroughly through it here: Google Analytics custom dimension not working: gtag set() method issues
to add properties you need to use 'set' together with 'event'. And also configure Special definitions in GA.
For example
const handleUserPropertiesNePetro = () => {
gtag('set', 'user_properties', {
custom_client_character: 'Halerik'
});
gtag('event', 'user_properties');
};