# 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)](/content/speak-with-us?utm_source=docs-site/index.html)

## Overview [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#overview/index.html)

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](/content/docs/consent/guides/google-tag-manager-consent-mode/index.html) instead.

## Prerequisites [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#prerequisites/index.html)

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](/content/docs/data-mapping/guides/adding-systems-manually/index.html) now.
- At least one privacy notice configured. Read how to [configure privacy notices](/content/docs/consent/guides/privacy-notices/index.html) now.
- At least one privacy experience configured. Read how to [configure privacy experiences](/content/docs/consent/concepts/fundamentals/privacy-experiences/index.html) now.
- Installed `Fides.js` on your web site. Read how to [install fides.js](/content/docs/consent/guides/install-fides/index.html) now.

## Basic Usage [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#basic-usage/index.html)

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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#default-google-consent-mode-mappings/index.html)

| Fides Consent Key | Google Consent Types |
| --- | --- |
| `analytics` | `analytics_storage` |
| `advertising` | `ad_storage`, `ad_personalization`, `ad_user_data` |
| `functional` | `functionality_storage`, `personalization_storage` |
| `data_sales_and_sharing` | `ad_storage`, `ad_personalization`, `ad_user_data` |
| `marketing` | `ad_storage`, `ad_personalization`, `ad_user_data` |

## Google Consent Types [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#google-consent-types/index.html)

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)](https://developers.google.com/tag-platform/security/guides/consent).

## Custom Mappings [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#custom-mappings/index.html)

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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#graceful-handling-of-missing-keys/index.html)

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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#checking-consent-state/index.html)

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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#complete-example/index.html)

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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#integration-behavior/index.html)

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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#integration-with-google-tag-manager/index.html)

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](/content/docs/consent/guides/google-tag-manager-consent-mode/index.html) which provides additional configuration options through the GTM interface.

## Debugging [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#debugging/index.html)

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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#troubleshooting/index.html)

### gtag() not found [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#gtag-not-found/index.html)

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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#consent-not-applying-to-google-services/index.html)

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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#tags-still-firing-without-consent/index.html)

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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#best-practices/index.html)

### Setting Default Consent [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#setting-default-consent/index.html)

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

```javascript
// 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 [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#regional-defaults/index.html)

You can set different default consent values for different regions:

```javascript
// 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? [Permalink for this section](/content/docs/consent/guides/google-consent-mode-v2#whats-next/index.html)

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

- [Configure the GTM Consent Mode template](/content/docs/consent/guides/google-tag-manager-consent-mode/index.html) for additional GTM-specific features
- [Customize the appearance](/content/docs/consent/guides/css-styling/index.html) of your privacy experiences
- [Configure additional privacy notices](/content/docs/consent/guides/privacy-notices/index.html) for different data uses
- Learn about [Google's Consent Mode best practices (opens in a new tab)](https://developers.google.com/tag-platform/security/guides/consent)
