My Google Consent Mode Solution

Hello everyone,

so I think a lot of people have issues with the google consent mode and with all due respect I think the documentation is lacking and even wrong sometimes.

The documentation says:

However the issue here is the following: If you set up google consent in code, that does not trigger any new event, nor is it available as trigger (neither api nor in the dashboard).

That basically means on first Pageview you’ll send a G100 event and only after the user accept cookies and goes to another page the variable will have changed and a new events get send. Which obviously makes you lose a lot of data.

My solution has been this:

I have duplicated my Google Tags, once with G100 and once with G111.

On first page view it will send the G100 one, the other ones are blocked by the purposes (which itself is really weird as you can only attach one purpose to a tool). However after those purposes have been sent I then load the G111 ones (zaraz.sendQueuedEvents())

As they have been queued it should be the same event and deduplicate on Google’s side.

For the G100 I set a blocking trigger (consent is true) so that on the upcoming pageviews and actions it won’t get triggered again.

Later I also only wanted to solve that in the EU as it’s not necessary on a lot of other countries.

This snippet still has a lot of issues.

{{system.device.location.isEUCountry}} can be undefined and will as literal become nothing therefore leading to a syntax error => if (===1)

my solution here was to create a simple isEuCountryfunction:

const isEuCountry = (val) => {
  if !!val return false 
  return val === 1
}

Also the getCookie function I didn’t use it as it looks to complicated and I’m just using a system variable, but it seems wrong to me:

If no cf_consent cookie is sent get Cookie will be false and there it will send queued events. If cookies are set to true (purpose given) getCookie will be true and sendQueued events won’t be sent (as they’ve been sent already, however they are not queued anyway…

If cookie is set to false (no purpose given) getCookie will be true and it won’t send queued events, but you change it directly before anyway (so next time you’ll send) leading to incomplete data.

Just make your life easy and do setAll(true) and then sendQueuedEvents() if you want to ignore for not EU countries.

Also this is just checking the first purpose and not all.

Also if your cookies are set and you are in an EU country this will show the modal on every pageview, which maybe was the initial idea.

I think the documentation needs some updates…

Please let me know any questions and mistakes.I want to be certain of that solution as well.

The documentation was updated: Google Consent Mode · Cloudflare Zaraz docs

1 Like

Thank you for updating so fast.

I think there is still a small issue, relevant for some:

The way the documentation is written it seems not like an updated event is sent to Google, but it will only be on subsequent events, which can reduce data size significantly if you have a lot of one-page visits.

I’m also unsure if it even works, if you never have sent a default consent to Google.

The ideal case would be that you send Google an actual update event when the consent changes as they wish for here:

I don’t exactly know what is happening under the hood, but in zaraz.debug I couldn’t see any calls happening to Google on update state, It only as describes in the documentation sends the info with the normal event on subsequent events.

The ideal solution would be send default consent, and update consent. in between it’s sending the pageview