Google Tag Manager - dynamically send custom events with their params to Google analytics
Asked Answered
F

3

7

I'm using Google Tag Manager (aka: GTM) to send events to my Google Analytics 4 account, some of them are custom that developers send thru the code like that:

dataLayer.push({
    event: 'CA:some-event',
    a: 1, // custom param
    b: 2  // custom param
})

I defined a Trigger in GTM to catch all events that start with "CA:*" (as regex) and then i defined a new Tag: "Google Analytics: GA4 Event" to be invoked when the trigger fired and send the event to GA4.

I'm getting the events successfully to my GA4 account but the problem is that all params, a and b in my example, are not sent as they are not mapped to be sent from GTM layer within the GA event.

I can define Variables in GTM specifically for them but it's not dynamic and it means that every time a developer needs to send a new custom event he'll need to go to the GTM account (and usually they don't have access to it), add the variables and it makes the whole solution semi-automatic and not dynamic enough.

I hope it's clear.

Any suggestions here?

Fumikofumitory answered 7/2, 2023 at 18:49 Comment(0)
F
1

i ended with the following solution:

  1. I changed the way I'm sending the event to be:
dataLayer.push({
    event: 'CA:some-event',
    data: {
        a: 1, // custom param
        b: 2  // custom param
    }
})
  1. set a variable in GTM called "Custom Event Data" based on the data property of the event

  2. set the GA4 event tag to send it to GA4

  3. set a new Custom Dimension in GA4 called "Custom Event Data" based on the data property

The limitation is that I cannot use a and b directly in GA4 as a native fields but at least I can see the variation of them in the GA4 reports

Fumikofumitory answered 11/2, 2023 at 20:53 Comment(0)
K
0

Unfortunately there is no easy way to manage GTM as the way you want. Hope they can allow us to use just JavaScript object to send as event parameter. (They only allow Ecommerce DataLayer at this time)

But looks like your developer can decide the event parameter themselves. So the option here is if they don't have access to GTM. They can just tell the one who is handling the GTM that their new implementation. So the GTM guy can modify based on it.

If your scenario is the changing is a lot and it really need to be automatic. Then GTM API might be the way. (But it also take some times for developer to integrate with it)


I used to manage more than 10+ properties and more than 30+ new events needs to add in a week.

So I choose Google Sheet(with Google App Script) to manage the GTM more easily.

The point here is there are still some ways to make it more automatic. Just need to leverage is it worth it do develop.

Kermit answered 8/2, 2023 at 1:14 Comment(0)
M
0

GTM as of now has "Event Settings" variables where you can define multiple custom data properties and reuse them, somewhat alleviating the PITA of mapping custom properties for each individual tag.

https://support.google.com/tagmanager/answer/13438771?hl=en

Mountfort answered 1/10 at 21:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.