Google Consent Mode Integration with UniConsent CMP

Before you get started, you need to sign up for UniConsent and obtain a license ID for your website or app.

Google Consent Mode is an API that allows you to send anonymous event data to Google Ads, Campaign Manager, Display & Video 360, Search Ads 360, and Google Analytics.

If you don't have consent mode v2 implemented, you won't have the option to remarket/personalize ads to these audiences in the future. To retain measurement for these audiences, you should implement consent mode V2 by the end of 2024 for EEA users.

UniConsent seamlessly integrates with Google Consent Mode. There is no need for any special configuration to enable this integration, as long as you have installed UniConsent CMP tags on your web pages either manually or via the Google Tag Manager. You can turn this off at your CMP dashboard if you don't use Consent Mode.

You can find instructions about how to install UniConsent via Google Tag Manager at https://www.uniconsent.com/docs/tutorials/gtm-integration.

You can use the Google-recommended consent message if you only use Consent Mode but not the IAB TCF/IAB GPP API.

We use cookies to provide you with the best possible experience. They also allow us to analyze user behavior in order to constantly improve the website for you. <a class="font-bold underline cursor-pointer" href="https://business.safety.google/privacy/">Privacy Policy</a>

Node: You must implement the following default consent status script to make Google Consent Mode V2 work if not using Google Tag Manager.

Place the following tag just before the UniConsent CMP tag and before your Google tags or any other advertising tags:

<script>
(function() {
    if(!window['gtag']) {
        window['dataLayer'] = window['dataLayer'] || [];
        window['gtag'] = function(){window['dataLayer'].push(arguments);}
    }
    window['gtag']('set', 'developer_id.dZTcxZD', true);
    window['gtag']('consent', 'default', {
        ad_storage: 'denied',
        functionality_storage: 'denied',
        personalization_storage: 'denied',
        analytics_storage: 'denied',
        ad_user_data: 'denied',
        ad_personalization: 'denied',
        security_storage: 'granted',
        wait_for_update: 1000
    });
    window['gtag']("set", "ads_data_redaction", true);
    window['gtag']("set", "url_passthrough", false);
})();
</script>

or use the short tag:

<script src="https://cmp.uniconsent.com/v2/stubgcm.min.js"></script>

The above code delays all the Google tag cookies until the user grants consent, except for security_storage.

You can update the values of ads_data_redaction and url_passthrough based on your requirements.

Note: If you set url_passthrough to true, Google tags will append _gl or _ga IDs to your URLs and pass data via the URLs. If you don't want GA4 to modify your URLs and append _gl parameters, you can set it to false.

If some of the options are not required by default in your country, you can change the value to be granted. For example:

<script>
  window.dataLayer = window.dataLayer || []
  function gtag() {
    dataLayer.push(arguments)
  }
  gtag('consent', 'default', {
    functionality_storage: 'granted',
    security_storage: 'granted'
  })
</script>

If Google Tag Manager is already set up on your website, ensure that you place the GTM script right after the Custom Consent Mode Script and before the UniConsent tag.

If Google Tag Manager isn't set up on your website, follow the steps below:

  1. Register/Establish a Google Tag Manager Account and create a container.
  2. Go to the Google Tag Manager Dashboard and select the Container ID from the top navigation panel.
  3. Insert the GTM script between the custom script and the UniConsent tag. Also, remember to add the <noscript> element right after opening the <body> tag.

Then follow the instructions at https://www.uniconsent.com/docs/tutorials/gtm-integration to setup UniConsent CMP via Google Tag Manager.

Google consent typeUniConsent Simple Mode consent typePurpose
ad_storageTargeting and AdvertisingTo enable advertisement cookies.
analytics_storagePerformanceTo enable analytics cookies.
functionality_storageFunctionalityTo enable functional cookies for website functionality and settings.
personalization_storageFunctionalityTo enable functional cookies for user personalization.
security_storageStrictly NecessaryTo enable necessary cookies for website security and protection, user UI preferences, etc. Such cookies do not require consent.
ad_user_dataTargeting and AdvertisingTo enable advertisement cookies to set consent for sending personal data to Google core platform service.
ad_personalizationTargeting and AdvertisingTo enable advertisement cookies to use data for ad personalization such as remarketing.
PurposeDescriptionGoogle tag behavior when Purpose is denied
Store and/or access information on a devicead_storage = deniedad_storage = denied ad_user_data = denied
Create a personalised ads profilead_personalization = deniedad_personalization = denied
Select personalized adsad_personalization = deniedad_personalization = denied
Measure ad performancead_user_data = deniedDisables the Google signals feature in Google Analytics (for web tags only).
Apply market research to generate audience insightsDisables the Google signals feature in Google Analytics (for web tags only).
Develop and improve productsDisables the Google signals feature in Google Analytics (for web tags only).

1. Use Google Tag Assistant

Find Consent at the left side and click, then click Consent tab at right side. You should see something like the following:

How to confirm UniConsent CMP for Google Consent Mode is workingHow to confirm UniConsent CMP for Google Consent Mode is working

You should not see any warning messages in your developer console in browser from UniConsent CMP.

You can install UniConsent Consent Validator to verify Consent Mode data is passing on your webpages.

Verify Consent Mode is working with UniConsent Consent ValidatorVerify Consent Mode is working with UniConsent Consent Validator

4. Use DataLayer API:

Enter window.dataLayer = window.dataLayer || []; into console of your browser, you should find a section consent, update.

{
    "0": "consent",
    "1": "update",
    "2": {
        "ad_storage": "granted",
        "ad_user_data": "granted",
        "analytics_storage": "granted",
        "functionality_storage": "granted",
        "personalization_storage": "granted",
        "ad_personalization": "granted",
        "security_storage": "granted"
    }
}

You can use the following Javascript API to access the Google Consent Mode Data:

(function waitCMP() {
  var readyCMP
  if (!readyCMP && window['dataLayer']) {
    window['dataLayer'].forEach(function (event) {
      if (event['event'] === 'unic_data') {
        readyCMP = 1
        console.log(event['CONSENT_MODE'])
      }
    })
  }
  if (!readyCMP) {
    setTimeout(waitCMP, 100)
  }
})()
  1. Google Consent Mode Enabled, but Default Status Stub Code is Missing

    Issue: You might encounter an error message in the Validator or developer console:

    Error: Consent Mode Default Status is not added.

    Solution: Add the Default Status stub code at the top of your pages to resolve this issue. You can follow the instructions here: Consent Mode Default Status Tag Installation.

  2. Google Consent Mode Enabled, but Default Status Stub Code is Added After Google Tags

    Issue: If the Default Status stub code is added after your Google tags, you may see the following error message in the Validator or developer console:

    Error: Your Google tags are loaded before Consent Mode Default Status and CMP.

    Solution: Ensure the Default Status stub code is added at the very top of your pages, before any Google tags. Follow the guide here: Consent Mode Default Status Tag Installation.

  3. Google Consent Mode Enabled via Google Tag Manager, but Not All Google Tags Are Managed in Google Tag Manager

    Issue: When some Google tags are not managed in Google Tag Manager, you might see errors similar to those described above.

    Solution: Either add the Default Status stub code at the top of your pages or ensure all your Google tags are managed within Google Tag Manager. Refer to the guide: Consent Mode Default Status Tag Installation.

  4. IAB TCF Stub Code is Missing

    Issue: The IAB TCF stub code is not included, leading to potential errors.

    Solution: Add the IAB TCF stub code at the top of your pages. Follow the instructions here: Stub Codes Installation.

  5. IAB GPP Stub Code is Missing

    Issue: The IAB GPP stub code is missing from your implementation.

    Solution: Include the IAB GPP stub code at the top of your pages. You can find the relevant guide here: Stub Codes Installation.

  6. USP API Stub Code is Missing

    Issue: The IAB USP stub code is not present.

    Solution: To resolve this, add the IAB USP stub code at the top of your pages. Detailed instructions are available here: Stub Codes Installation.

When you encounter issues with missing Consent Mode or TCF (Transparency and Consent Framework) signals on your Google tags, it's essential to start the troubleshooting process with UniConsent support team rather than contacting Google directly.

If you are a Google client, please reach out to us via email at support+google@uniconsent.com or post in the UniConsent Support Community Forum. The UniConsent support team will provide a technical response within 1 business days.

Contact via Phone +441134678278 for urgent issues.

Still have questions?

Contact us: support@uniconsent.com or find livechat widget at your dashboard.