How to enable Consent Mode v2 Basic

Here’s how to correctly set consent mode v2 basic implementation with a step by step walkthrough.

Google’s Consent Mode v2 is the updated consent solution to keep effectively using Google’s Marketing Platform in the Cookie-less web ecosystem unfolding in 2024.

In this guide I’ll walk you trough the basic configuration of Consent Mode v2.

The main difference to consider when deciding to implement the advanced consent mode v2 or the basic one, is understanding the tag firing behavior in the two scenarios.

  • In the basic version of Consent Mode, we are doing asynchronous tagging via GTM’s consent overview feature. This means, that where Google finds consent for the appropriate and required consent levels, it will fire the tag. Where it doesn’t find the correct consent level, Google Tags will simply not fire.
  • In the advanced version of Consent Mode, all tags fire unconditionally from the consent state; the consent state is only going to influence the data quality. So a non consented tag will fire without any cookie association, resulting in a simple ping, which we won’t be able to see in the frontend of our tools (such as Analytics, Ads and so on). All the consented tags firing, will instead keep working as usual, carrying the detailed information linked to the cookie stored in the user’s device.

It’s important to understand that the advanced version of Consent Mode is crucial to train the Machine Learning and AI models fueling GA4 and Smart Bidding. Therefor, it’s always advisable to implement Consent Mode in its advanced version. Here’s a guide on how to implement Google Consent Mode v2 Advanced with Google Tag Manager.

difference between consent mode basic and advanced
Screenshot from Google Marketing Expert’s coverage of the different behavior of tags with Consent Mode Advanced vs Basic.

Here’s how to set Consent Mode v2 up in its basic setup. Consider that you’d might choose to use Google Consent Overview in Google Tag Manager, and you’ll still need to have a Google compatible CMP Provider to comply with GDPR and other regulations.

Because the configuration depends a lot on the CMP you’re using, we’re going to show a manual implementation of conditional tagging, which is replicable for any kind of CMP you’re using.

In this guide, we will show how to set it up with Iubenda, but the same approach applies to other CMPs.

  • Fetch the Cookie values placed by your CMP when the user expresses consent
  • Extract those values trough GTM Variables
  • Utilize those variables to create triggers in GTM
  • Adapt the Tags Firing behavior based on the level of consent granted, for the tags to fire.

Consider that in order to follow this example, you’ll have to slightly tweak your standard Iubenda Cookie Solution code as follows. You can follow a full guide here.

This is a typical starting point of the Iubenda default CS code:

<script type="text/javascript">
    var _iub = _iub || [];
    _iub.csConfiguration = {
        "lang": "en",
        "siteId": XXXXXX, //use your siteId
        "cookiePolicyId": YYYYYY, //use your cookiePolicyId
        "banner": {
            "position": "float-top-center",
            "acceptButtonDisplay": true,
            "customizeButtonDisplay": true
        }
    };
</script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/iubenda_cs.js" charset="UTF-8" async></script>

And this is how it’s going to look after you’ve added the necessary callbacks:

<script type="text/javascript">
    var _iub = _iub || [];
    _iub.csConfiguration = {
        "lang": "en",
        "siteId": XXXXXX, //use your siteId
        "cookiePolicyId": YYYYYY, //use your cookiePolicyId
        "banner": {
            "position": "float-top-center",
            "acceptButtonDisplay": true,
            "customizeButtonDisplay": true
        },
        "callback": {
                  onPreferenceExpressedOrNotNeeded: function (preference) {
                    dataLayer.push({
                      iubenda_ccpa_opted_out: _iub.cs.api.isCcpaOptedOut(),
                    });
                    // preferences parameter may be undefined if both GDPR and LGPD do not apply
                    // we may need the line below to find USPR preferences instead of relying
                    // on preferences parameter
                    var otherPreferences = _iub.cs.api.getPreferences();
                    if (otherPreferences) {
                      var usprPreferences = otherPreferences.uspr;
                      if (usprPreferences) {
                        for (var purposeName in usprPreferences) {
                          if (usprPreferences[purposeName]) {
                            dataLayer.push({
                              event: 'iubenda_consent_given_purpose_' + purposeName,
                            });
                          }
                        }
                      }
                    }
                    if (!preference) {
                      dataLayer.push({
                        event: 'iubenda_preference_not_needed',
                      });
                    }
                    else if (preference.consent === true) {
                      dataLayer.push({
                        event: 'iubenda_consent_given',
                      });
                    }
                    else if (preference.consent === false) {
                      dataLayer.push({
                        event: 'iubenda_consent_rejected',
                      });
                    }
                    else if (preference.purposes) {
                      for (var purposeId in preference.purposes) {
                        if (preference.purposes[purposeId]) {
                          dataLayer.push({
                            event: 'iubenda_consent_given_purpose_' + purposeId,
                          });
                        }
                      }
                    }
                  }		
        }
    };
</script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/iubenda_cs.js" charset="UTF-8" async></script>

Iubenda, the CMP that we are using on all of our projects, places a 1st party cookie on the users’s browser when they have expressed their consent choices. This cookie has the following name:

_iub_cs followed by the site ID of your Iubenda Project. In this example, it is

_iub_cs-23812683

If we use the browsers inspector, and we move to “Application”, isolating the iub_cs cookie, we will be able to read its values. In this case, because the source website only has necessary and measurement cookies on the property, we will see only the consent for variable 1 and variable 4.

chrome web tools inspection of iubenda cookie

Take note of the name of the cookie, and of the string of content within it, and move to the next step.

In Google Tag Manager, select your container, then go to Variables, and add a new 1st Party Cookie Variable. Compile it as follows, using the name of your own CMP cookie. Make sure to select “URI-decode cookie”.

setting up first party cookie iubenda for consent mode v2 basic

Then, create one variable per each level of consent you need, based on the cookies you’re utilizing. To do this, select the variable time “RegEx Table”, and map the meaning of each level of consent. Consider that the necessary cookies, will set the cookie to granted in any case.

setting up first level cookie iubenda for consent mode v2 basic

setting up second level cookie iubenda for consent mode v2 basic

setting up third level cookie iubenda for consent mode v2 basic

setting up fourth level cookie iubenda for consent mode v2 basic

setting up fifth level cookie iubenda for consent mode v2 basic

Technically now you have to use the variables you’ve created, to create triggers that we will use as blocking triggers; they will operate the opposite of the traditional way of how a trigger works. Instead of enabling a tag’s firing status, it will impede it.

So you’re going to create the following triggers, and you can download my GTM Container to study the configuration.

  • General Consent Given
  • Per purpose Consent Given (5 Triggers in this case)
  • Per Purpose Consent not Given (5 Triggers in this case)
  • Consent not needed

Here you can download the Json to see how to implement each trigger.

Now you’re ready to use your “consent not given” triggers as blocking triggers to all your tags. The process is the same for every tag. You need to know what kind of cookie is utilized by each tag, to understand what kind of consent level they need to fire.

Here’s the modified version of a Google Analytics 4 Tag, before and after implementation.

conditional tag blocking consent mode basic 1
Standard GA4 tag firing, independent from consent
enable conditional tag blocking consent mode basic 1
Basic Consent Mode implementation. The Tag fires only if it has the right level of cookie consent.

While in the configuration of the Advanced Consent Mode we will fire all essential tag at the initialization stage, here we’ll need to use a state of the browser which is surely set after consent has been set. In this case, we will create a GTM trigger at the “Dom Ready” event, on all pages, and use that as trigger.

We suggest you to switch your firing triggers from “window loaded”, or “page loaded”, or “initialization”, to Dom Ready for optimal results, with the basic configuration, while you should utilize “initialization” for the advanced configuration.

Once you’ve set your test tag on “Dom Ready” and you’ve made sure that consent is automatically set to “denied” for all variables trough the script loaded before your Google Tag Manager container loads, you’re ready to debug with Google Tag Assistant.

Use the preview mode of your Google Tag Manager container, and observe the states of the browser trough page load.

If you’ve set things correctly you’ll notice:

  • At consent initialization, your CMP banner loads.
  • An event called “Consent” fires
    • Navigate to the “Consent” tap on the “Consent” event, and notice how all the levels are set to “denied”, if you have refused consent.
  • Now, as the Dom Ready event fires, you’ll notice that your tag didn’t fire based on consent.
  • Viceversa, if you did give consent, the tags should be firing after the consent event has been set, and the Dom was ready.
consent mode status trough gtm

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.