alinemorelli / react-gtm

React Google Tag Manager
MIT License
658 stars 140 forks source link

What is the equivalent of gtag('consent', 'update', {'ad_storage': 'granted'} #103

Closed jkohlin closed 2 years ago

jkohlin commented 2 years ago

If I want to perform the following gtag('consent', 'update', {'ad_storage': 'granted'} GTM preview will list Consent like this:

image

What is the equivalent using TagManager.dataLayer() ? Or perhaps I should use another method?

NEDDL commented 2 years ago

@jkohlin I am looking for the same thing, were you able to find a solution for consent management?

jkohlin commented 2 years ago

Yes, sorry. Forgot about this question. This works: TagManager.dataLayer({dataLayer: ['consent', 'update', { ad_storage: 'granted' }]})

dopry commented 1 year ago

@jkohlin does it though? when I use tag assistant to inspect, I don't see consent events being fired by just passing an array. An array is not equivalent to an arguments object passed into the data layer by the gtm examples. I needed to implement a helper to make this work for me.

gtag.ts

import TagManager from "react-gtm-module";

export function gtag(...args: any[]) {
  TagManager.dataLayer({ dataLayer: arguments });
}
jkohlin commented 1 year ago

@dopry I don't remember how we set this up in tag manager and I don't have access to it anymore but this worked in our case anyway.

cyango commented 6 months ago

Just passing by to understand if someone still recommends this solution?