Skip to content
Configuring Google Consent Mode v2

Consent Management: Configuring Google Consent Mode v2

10minFidesConsent Management
This tutorial requires Fides Cloud or Fides Enterprise. For more information, talk to our solutions team. (opens in a new tab)

In this tutorial, we'll configure Google Consent Mode v2 to respect the end-user consent choices provided by Fides.js.

Overview

The Google Consent Mode v2 integration automatically syncs Fides consent with Google's Consent Mode v2 API via gtag(). This enables proper consent management for Google Analytics, Google Ads, and other Google services that respect Consent Mode.

This integration provides:

  • Direct gtag() integration - Works with Google Tag Manager or standalone gtag.js
  • Automatic consent syncing - Responds to all Fides consent events
  • Flexible mapping - Map Fides consent keys to Google's standard consent types
  • Graceful degradation - Only processes consent keys that exist in both the mapping and Fides configuration

This integration provides a direct implementation of Google Consent Mode v2 using gtag(). If you're using Google Tag Manager (GTM), you may prefer the GTM Consent Mode template integration instead.

Prerequisites

For this tutorial you'll need:

  • A Fides Cloud or Fides Enterprise account
  • The role of Owner or Contributor for your Fides organization.
  • Google Analytics, Google Ads, or Google Tag Manager (GTM) installed on your website
  • At least one system with a data use on your Data Map. Read how to add systems to the Data Map now.
  • At least one privacy notice configured. Read how to configure privacy notices now.
  • At least one privacy experience configured. Read how to configure privacy experiences now.
  • Installed Fides.js on your web site. Read how to install fides.js now.

Basic Usage

The simplest way to integrate Google Consent Mode v2 is to use the default mappings:

<!-- Load gtag.js or Google Tag Manager -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'GA_MEASUREMENT_ID');
</script>
 
<!-- Load Fides.js -->
<script src="path/to/fides.js"></script>
 
<script>
  // Initialize Google Consent Mode v2 integration
  Fides.gcm();
</script>

This will automatically sync Fides consent to Google using the following default mappings:

Default Google Consent Mode Mappings

Fides Consent KeyGoogle Consent Types
analyticsanalytics_storage
advertisingad_storage, ad_personalization, ad_user_data
functionalfunctionality_storage, personalization_storage
data_sales_and_sharingad_storage, ad_personalization, ad_user_data
marketingad_storage, ad_personalization, ad_user_data

Google Consent Types

Google Consent Mode v2 supports the following standard consent types:

  • ad_storage - Enables storage (such as cookies) related to advertising
  • ad_personalization - Enables storage related to advertising personalization
  • ad_user_data - Sets consent for sending user data to Google for advertising purposes
  • analytics_storage - Enables storage (such as cookies) related to analytics
  • functionality_storage - Enables storage that supports the functionality of the website or app
  • personalization_storage - Enables storage related to personalization
  • security_storage - Enables storage related to security such as authentication functionality, fraud prevention, and other user protection

Learn more about Google Consent Mode in the official Google documentation (opens in a new tab).

Custom Mappings

You can customize the consent mappings to match your specific Google implementation and privacy notice structure:

Fides.gcm({
  purposeMapping: {
    analytics: ['analytics_storage'],
    marketing: ['ad_storage', 'ad_personalization', 'ad_user_data'],
    functional: ['functionality_storage', 'personalization_storage'],
    essential: ['security_storage']
  }
});

Graceful Handling of Missing Keys

The integration intelligently handles cases where not all mapped consent keys are configured in Fides. It will only process consent for keys that exist in both the purposeMapping and the Fides consent object.

For example, if your mapping includes essential but you haven't configured an "essential" privacy notice in Fides, the integration will skip that key and continue processing the others without errors.

Checking Consent State

You can check the current Google consent state using the consent() method:

const gcm = Fides.gcm();
 
// Attempt to get current Google consent state
const state = gcm.consent();
 
console.log(state);
// Output: null

Note: Google's Consent Mode API does not provide a public method to read consent state. The consent() method will return null. Use Fides.consent as the source of truth for user consent preferences.

Complete Example

Here's a complete example showing how to install Google Analytics with Consent Mode v2 and Fides.js:

<!DOCTYPE html>
<html>
<head>
  <!-- Google Analytics with Consent Mode v2 -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    
    // Set default consent state (denied by default for GDPR compliance)
    gtag('consent', 'default', {
      'ad_storage': 'denied',
      'ad_personalization': 'denied',
      'ad_user_data': 'denied',
      'analytics_storage': 'denied',
      'functionality_storage': 'denied',
      'personalization_storage': 'denied'
    });
    
    gtag('js', new Date());
    gtag('config', 'GA_MEASUREMENT_ID');
  </script>
  
  <!-- Load Fides.js -->
  <script src="https://privacy.example.com/fides.js"></script>
  
  <script>
    // Initialize Google Consent Mode v2 integration
    Fides.gcm({
      purposeMapping: {
        analytics: ['analytics_storage'],
        advertising: ['ad_storage', 'ad_personalization', 'ad_user_data'],
        functional: ['functionality_storage', 'personalization_storage']
      }
    });
  </script>
</head>
<body>
  <!-- Your website content -->
</body>
</html>

Integration Behavior

The Google Consent Mode v2 integration:

  1. Listens to Fides events - Automatically responds to FidesReady and FidesUpdated events
  2. Syncs consent immediately - If Fides consent is already available when initialized, it syncs immediately
  3. Updates via gtag() - Uses gtag('consent', 'update', {...}) to update consent state
  4. Graceful degradation - If gtag() is not detected, the integration logs debug information but does not error
  5. Flexible key handling - Only processes consent keys present in both the mapping and Fides consent

Integration with Google Tag Manager

This integration works seamlessly with Google Tag Manager. When GTM is present on the page, the gtag() function is automatically available through the GTM data layer.

If you're using GTM's Consent Mode template, you may prefer the GTM Consent Mode template integration which provides additional configuration options through the GTM interface.

Debugging

To debug the integration, listen to Fides events to see when consent changes are applied:

window.addEventListener("FidesUpdated", (event) => {
  console.log("Fides consent updated:", event.detail);
});

This will show you the current consent state whenever it changes, which you can then verify against your Google Tag Manager or Google Analytics console.

Troubleshooting

gtag() not found

If you see the message "gtag() not found. Ensure Google Tag Manager or gtag.js is loaded", verify:

  1. Google Tag Manager is loaded before the integration: Check for window.gtag
  2. Or, gtag.js is loaded: Check that the Google Analytics script is present
  3. Fides.js is loaded after gtag is available

Consent not applying to Google services

If consent doesn't seem to be applying to Google services:

  1. Check the browser console for error messages
  2. Listen to Fides events (see Debugging section above) to verify consent is being updated
  3. Verify your purposeMapping includes all the consent types you need
  4. Confirm your Fides privacy notice cookie keys match what you're using in the mappings
  5. Check that you've set default consent to 'denied' before initializing gtag

Tags still firing without consent

If Google tags are still firing without consent:

  1. Ensure you set default consent to 'denied' before calling gtag('config', 'GA_MEASUREMENT_ID')
  2. Verify that your Google tags in GTM (if using GTM) have consent checks configured
  3. Check that Consent Mode is properly enabled in your Google Analytics property settings

Best Practices

Setting Default Consent

For GDPR (General Data Protection Regulation) compliance, set default consent to 'denied' before loading Google services:

// Set default consent BEFORE gtag('config', ...)
gtag('consent', 'default', {
  'ad_storage': 'denied',
  'ad_personalization': 'denied',
  'ad_user_data': 'denied',
  'analytics_storage': 'denied',
  'functionality_storage': 'denied',
  'personalization_storage': 'denied'
});

Regional Defaults

You can set different default consent values for different regions:

// Default for GDPR regions (denied by default)
gtag('consent', 'default', {
  'ad_storage': 'denied',
  'analytics_storage': 'denied',
  'region': ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE']
});
 
// Default for non-GDPR regions (granted by default)
gtag('consent', 'default', {
  'ad_storage': 'granted',
  'analytics_storage': 'granted'
});

Fides handles geolocation and region-specific consent automatically. These regional defaults in gtag provide a fallback in case Fides hasn't loaded yet.

What's next?

Now that you have Google Consent Mode v2 integration configured, you might want to: