Google Consent Mode v2 for WordPress – implementation example

Learn how to use Google Consent Mode v2 with WordPress and with Beautiful Cookie Banner WordPress plugin. This article gives you a brief intro in Google Consent Mode and shows an easy way how to optimize WordPress with Beautiful Cookie Banner plugin.

You get a much better tracking accuracy as the traffic and conversion you are missing due to user opt-out will be modelled.

From March on Google Tracking products like Google Ads tracking, Google Analytics 4 and Google Floodlights need consent mode to work properly.

What options do you have?

You can set up the Basic implementation or the Advanced version of it.

Basic

You just push the consent information additionally to the dataLayer. That’s it. Official docs: https://developers.google.com/tag-platform/security/concepts/consent-mode?hl=en

If you have already a working set up, you just set up consent mode additionally. Then additional Information, which is required by google, is added to the google tracking requests.

If you start from scratch you first make sure, that the tags fire when there is consent. You can do this with the “blocking feature” of the premium plugin or with Google Tag Manager (recommended) see here for more info. If that is set up, just add the consent mode signals to get the consent mode infos additionally.

Advanced

You push the consent information to the dataLayer, same as Basic. Additionally you fire all Google Tags always. Independent from the user’s consent. You rely here on the Google tags to handle the data in a GDPR friendly way.

This version is quite controversial from a data privacy point of view. This is why I focus in this article on how to implement the basic version.

Disclaimer: This article does not contain any legal advice of any kind. It only describes the technical implementation.

For Google Tags the important parameters are:

  • analytics_storage
  • ad_storage
  • ad_user_data (new in v2)
  • ad_personalization (new in v2)

All these examples use this Cookie Banner WordPress Plugin

Configuration example

Compliance Type: Differentiated Consent

Example of WordPress cookie banner using google consent mode v2
Example Config for Consent Banner 1 for Google Consent Mode.

The Banner 2 config looks similiar

Example screen Cookie Banner 2 for Google consent mode
Categories for Cookie Banner 2

Let’s assume you want to allow all your Google tracking tags to collect data on “Marketing” consent and you want to allow personalization.

This would be the configuration of the Beautiful Cookie Banner WordPress Plugin then:

The “Google Consent Mode” tab looks exactly the same for Banner 1 and Banner 2.

Example of Google Consent mode v2 configuration for WordPress plugin
HINT: the Google Consent Mode Configuration screen looks different based on the chosen compliance type.

That’s it. Your tags still fire how you have configured them. They just have some additional parameters added to the request.

Result

Tool used in screenshots is Tag Assistant Companion.

On first page view, the user has not opted in to marketing, yet

Tag Assistant result consent mode v2 default

The user has opted in to marketing:

Tag Assistant result consent mode v2 update marketing tags

Next page view of user:

The default is still “denied” but the “update” with granted comes immediately after the default event.

Tag Assistant result consent mode v2 default and update on next page view

Variation configuration example 1: default for analytics_storage to be granted.

To have the consent mode category analytics_storage always granted. You can additionally toggle in consent mode configuration “tech”.

consent mode configuration: analytics_storage granted per default

This works because the “tech” cookie is configured on compliance screen as “default checked”.

consent mode configuration: analytics_storage granted per default - compliance settings

Now analytics_storage is granted by default already.

Tag Assistant result consent mode v2 default and update for analytics_storage  as default granted.

For more unofficial background information of consent mode and how to debug and test it, see this German blog post: markus-baersch.de/blog/consent-mode-2-0-faq/ Unfortunately it is in German, but the build in translation feature of the major browser can help with that.

And here is a good article in english: simoahava.com/analytics/consent-mode-v2-google-tags/

Next Step

How to test Google Consent Mode v2 implementation

Disclaimer: This article does not contain any legal advice of any kind. It only describes the technical implementation.