How to Integrate with Google Consent Mode v2
Google Consent Mode v2 allows you to control how Google tags behave based on user consent choices. This guide will walk you through the integration process step by step.
Prerequisites
Before starting, ensure you have:
- Access to your website's code or content management system
- Google Tag Manager or Google Analytics already set up on your site
- A consent management platform (like CookieForte) installed
Step 1: Configure Your Consent Banner
- Navigate to Websites and banners in your consent management platform
- Choose your banner from the list
- Click on Settings
- Enable the Google Consent Mode v2 setting
This setting ensures your consent banner communicates properly with Google's consent framework.
Step 2: Add the Consent Mode Script
You need to add a consent initialization script to your website before your Google Tag Manager or Google Analytics script loads.
Implementation Code
Add the following script to your website's <head> section, placing it before any Google tracking scripts:
<script> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('consent', 'default', { 'ad_storage': 'denied', 'analytics_storage': 'denied', 'functionality_storage': 'denied', 'personalization_storage': 'denied', 'security_storage': 'granted', 'ad_user_data': 'denied', 'ad_personalization': 'denied', 'wait_for_update': 500 }); gtag("set", "ads_data_redaction", true); gtag("set", "developer_id.dMmY1Mm", true); </script>
Understanding the Consent Parameters
Parameter | Default Value | Description |
---|---|---|
ad_storage | denied | Controls storage for advertising purposes |
analytics_storage | denied | Controls storage for analytics purposes |
functionality_storage | denied | Controls storage for website functionality |
personalization_storage | denied | Controls storage for personalization |
security_storage | granted | Controls storage for security (typically always granted) |
ad_user_data | denied | Controls sharing of user data for advertising |
ad_personalization | denied | Controls personalized advertising |
wait_for_update | 500 | Time in milliseconds to wait for consent updates |
Step 3: Verify Your Implementation
To ensure everything is working correctly, use the Google Tag Assistant Chrome extension:
Installation and Testing
- Install Google Tag Assistant: Add the extension from the Chrome Web Store
- Open your website in a new tab
- Access the side panel: Google tags should appear in the Tag Assistant side panel
- Navigate to tag details: Click on Tag → Pageview → Format
- Check consent status: Verify that ad_storage and analytics_storage show as "denied" or "granted" according to user Statistics and Marketing settings in CookieForte banner
What to Look For
- Initially, storage parameters should show as "denied" (before user consent)
- After user grants consent through your banner, the parameters should update to "granted"
- The consent state should match your banner's configuration
Troubleshooting
Common Issues
Script not loading: Ensure the consent script is placed before all Google tracking scripts in your HTML.
Consent not updating: Check that Enable Google Consentv2 is enable in CookieForte platform.
Best Practices
- Always set initial consent to "denied" for data protection compliance
- Use security_storage: 'granted' as it's typically required for basic website security