Setup Google Consent mode using Zaraz

Starting in March 2024 Google Ads will be negatively impacted if Google Consent is not being used with Google Analytics.

  • Updates to consent mode for traffic in European Economic Area (EEA): https://support.google.com/tagmanager/answer/13695607

Consent Management in Zaraz can be used to conditionally load GA4, but this is not the same thing as using Google Consent mode.

Google Consent mode has to be configured using gtag, is this possible through Zaraz? There’s a dataLayer compatiblity mode, but all it seems to do is convert dataLayer.push() calls to zaraz.track(). What about gtag consent calls?

Would love to use Zaraz, but if it hurts Google Ads campaigns this won’t be an option for us.

// How would this work with Zaraz?
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('consent', 'default', {
  'ad_user_data': 'denied',
  'ad_personalization': 'denied',
  'ad_storage': 'denied',
  'analytics_storage': 'denied',
  'wait_for_update': 500,
});

// Once consent is given, inform google
gtag('consent', 'update', {
  'ad_user_data': 'granted',
  'ad_personalization': 'granted',
  'ad_storage': 'granted',
  'analytics_storage': 'granted'
});
  • Google documentation: Upgrade to consent mode v2: https://developers.google.com/tag-platform/security/guides/consent?consentmode=basic#upgrade-consent-v2
2 Likes

Add the initial script with the denied settings to your website as per normal.

In Zaraz, select ‘Tools Configuration’ → Add new tool choosing custom HTML, name as required and trigger on page view, enter the consent part of the gtag script in script tags.

Then under Consent, assign the above custom tool to your required purpose e.g. retargeting/advertising.

To test, in Chrome open the dev tools, clear the cookies for the site.
Refresh the page so you see the cookie banner prompt, before accepting the cookie paste the script below into the console and check that the consent is set as denied.

(function(w, d, t) {
for (i of w[d])
t += JSON.stringify(i).replaceAll(/"\d{1,}":/g, “”) + “\n”;
console.log(t);
})(window, “dataLayer”, “”)

You should see:
{“consent”,“default”,{“ad_storage”:“denied”,“analytics_storage”:“denied”,“wait_for_update”:500}}
{“set”,“ads_data_redaction”,true}

Accept the cookie banner allowing all and then re-run the script above and you should see:
{“consent”,“default”,{“ad_storage”:“denied”,“analytics_storage”:“denied”,“wait_for_update”:500}}
{“set”,“ads_data_redaction”,true}
{“consent”,“update”,{“ad_user_data”:“granted”,“ad_personalization”:“granted”,“ad_storage”:“granted”,“analytics_storage”:“granted”}}

It seems like that might not be processed by Analytics.

Wouldn’t that just put a dataLayer array into the window? The same way as if you included the snippet directly without Zaraz/custom-HTML. All you’re testing is if pushing to the dataLayer array worked, which of course works with that snippet on a page. But will it be processed by Analytics?

I was under the impression that you had to use zaraz.track() and configure triggers in Zaraz to make Analytics actually process the event. If that is true, I don’t think using custom HTML to insert a script will do the trick.

See here for how to use Consent Mode with Zaraz: FAQ · Cloudflare Zaraz docs

2 Likes

Thanks. The FAQ mentions that a Google defined format like G111 should be used. Is there any documentation from them on this? And what about consent mode v2 parameters?

1 Like

Google took the parameter out of their docs, found it here - Archive.org: Manage consent settings (web) | Security and Privacy hub | Google for Developers

The current Consent Mode parameter in Zaraz seems to set an internal gcs parameter. There’s also gcd for Consent Mode V2 signals Consent Mode V2 For Google Tags | Simo Ahava's blog

It seems Consent Mode V2 signals are not supported yet by Zaraz. If that’s added, it might be helpful to create a wrapper to set these internal signal parameters, similar to what gtag does.

Hi @yoav_zaraz,
From what i seen in the documentation : FAQ · Cloudflare Zaraz docs

Since the value for Consent Mode may change per user or session, it is recommended to dynamically set this value using zaraz.set in your website code. For instance, use zaraz.set("google_consent", "G100") on page load, and zaraz.set("google_consent", "G111") after the user granted consent for Marketing and Analytics. In the Consent Mode field, select the + symbol, choose Event Property, and type google_consent as the property name. Zaraz will then use the latest value of the google_consent Event Property as the Consent Mode string.

I’m having difficulty figuring out how to use zaraz.set("google_consent", "G111") after the user has granted consent. Could you please provide guidance on how to trigger this event and execute the JavaScript?

Thank you.

Check out the Consent Mode v2 documentation: Google Consent Mode · Cloudflare Zaraz docs

That was quick, thanks!

Hey @yoav_zaraz

I think this solution is quite good, but not perfect. This solution is changing the behaviour of subsequent requests, but it doesn’t send signals or events to Google as they request.

There should be a mechanism how we can send events to google and not just updated PageView Events.

I understand that might be a deeper change for Zaraz, but I think it’s necessary to be able to provide a solution that works with GA.

Kind
Julian

Hey @juliantosun , it’s unclear to me what you mean by “it doesn’t send signals or events to Google as they request”. Many users have implemented Google Consent using the above method and everything is working well for them.

Hey @yoav_zaraz

Please see this post:

They are suggesting to always send a default option, and later send an update event.

I’ve implemented Google Consent for my site as well and I can see the request are working properly with zaraz.debug, but I’m still getting an error message in my GA4:

Google is talking about consent signals and not pageviews with attached consent all the time. And when I l look into classic Google debugging they have a debug view that lists specific events and consent is separated there.

I’m still getting an error shown in GA4 that I don’t send consent signals.

When I check in debug it shows the pageview with the consent signals.

What should I do?

how did you implement the default consent status?

So when I’m on my website for the first time this is getting sent to GA:

image

As well as a server-side Request: (which does not contain either gcs or G100

Once I approve the cookie banner. I’m sending another request (that was blocked by consent purpose)

And I get this call to GA

image

On every upcoming page only the updated consent tool is getting triggered:

image

From my understanding this is sending page view events to GA, with gcs information, but not an individual signal, like f.e. in this example:

Or read about consent mode pings here:

Since your debugger screenshots are showing gcs, it looks like you’re mixing up Consent Mode v1 and Consent Mode v2. I recommend getting rid of Consent Mode v1 and implementing the default Consent Mode v2 status at the beginning of your body element.