I have google analytics 4 being loaded via GTM, and i've been struggling with adding custom dimensions to the "enhanced measurement" events. after reading some other answers i've determined that yes, the dimensions work when set in the 'config'
call for the tracking id (which i can do in GTM under "fields to set"), but 'config'
seems like it noops on subsequent calls for an already configured tracker with GA4 (with UA it does something).
as discussed in the other questions, 'set'
operations don't seem to do anything, and i'm not manually dispatching the "enhanced collection" events so i can't manually specify the parameters in the call.
is there any way to add parameters to "enhanced measurement" events after the tracker is configured?
a minimal example:
gtag('set', {'dimension1': 'test1'})
gtag('config', 'G-XXXXX', {dimension2: 'test2'})
gtag('set', {'dimension3': 'test3'})
gtag('event', 'test', {send_to: 'G-XXXXXX', foobar: 'baz'})
the debugger shows the event parameters: en: test _ee: 1 ep.dimension2: test2 ep.foobar: baz
on a page navigation the automatic enhanced collection event looks like this: en: page_view ep.dimension2: test2 _et: 922
however when using an old GA account:
gtag('config', 'UA-XXXXXX')
gtag('event', 'test', {send_to: 'UA-XXXX', foobar: 'baz'})
it shows all the set dimensions: "dimension1": "test1" "dimension3": "test3" "&jsscut": "1" "hitCallback": [function] "hitType": "event" "eventCategory": "general" "eventAction": "test"
why does the G4 integration not pick up on set dimensions? and is there any way to modify dimensions after the tracker is configured other than including them on the event call
I have google analytics 4 being loaded via GTM, and i've been struggling with adding custom dimensions to the "enhanced measurement" events. after reading some other answers i've determined that yes, the dimensions work when set in the 'config'
call for the tracking id (which i can do in GTM under "fields to set"), but 'config'
seems like it noops on subsequent calls for an already configured tracker with GA4 (with UA it does something).
as discussed in the other questions, 'set'
operations don't seem to do anything, and i'm not manually dispatching the "enhanced collection" events so i can't manually specify the parameters in the call.
is there any way to add parameters to "enhanced measurement" events after the tracker is configured?
a minimal example:
gtag('set', {'dimension1': 'test1'})
gtag('config', 'G-XXXXX', {dimension2: 'test2'})
gtag('set', {'dimension3': 'test3'})
gtag('event', 'test', {send_to: 'G-XXXXXX', foobar: 'baz'})
the debugger shows the event parameters: en: test _ee: 1 ep.dimension2: test2 ep.foobar: baz
on a page navigation the automatic enhanced collection event looks like this: en: page_view ep.dimension2: test2 _et: 922
however when using an old GA account:
gtag('config', 'UA-XXXXXX')
gtag('event', 'test', {send_to: 'UA-XXXX', foobar: 'baz'})
it shows all the set dimensions: "dimension1": "test1" "dimension3": "test3" "&jsscut": "1" "hitCallback": [function] "hitType": "event" "eventCategory": "general" "eventAction": "test"
why does the G4 integration not pick up on set dimensions? and is there any way to modify dimensions after the tracker is configured other than including them on the event call
config
again doesn't seem to do anything or affect future events, with or without send_page_view
specified
– tomwoodward
Commented
May 10, 2023 at 20:04
Okay, dug the issue up. Google is a bit odd with how they push new stuff related to GA4. Somewhere last August Google rolled out a new feature. To ignore 'duplicate' config calls. And enabled it by default. While the idea of it seems a bit ridiculous, it bees even more ridiculous when you realise it was a sneak update without notifying us or documenting it.
Anyhow:
source
Yes, gtag.js' behavior is configured depending on the config of your GA4 property. There are more things you configure in your library through this ui. One of which would be cross-domain linking rules.
Thanks to Angela Grammatas and Todd Bullivant for helping figuring this out on Measure slack :)
Other than that, it's a bit odd to use both GTM and gtag() in parallel. Will lead to gathering of technical debt. It's much better to migrate all direct gtag() calls to GTM via dataLayer.
in addition to the correct info from @bnazaruk(that is STILL undocumented), I also found that subsequent calls to gtag('config',...)
overwrite values from previous calls instead of merging them. The documentation seems to suggest that they are merged rather than replaced and I feel like that was what it used to do a few years ago when I last had to set something like this up. To keep previous config
objects I also had to do this
const oldConfig =
window.dataLayer.find((args) => args['0'] === 'config')?.['2'] ?? {};
gtag('config', '<GA_KEY>', {
...oldConfig,
new_prop: 'blahblah'
});
which only adds in the first instance of a config call since that's the only one I care about, but you could easily change the find
call to a filter or reduce to get all of them