Update to Google Consent V2
Update to Google Consent V2
This article will guide you on how to update Google Consent to Version 2. You can find the official information here.
- Check your current <script> tag that's working with Google Tag or Google Analytics.Example (before the update):
<script async src="<https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied'
});
gtag('config', 'G-XXXXXXXXXX');
</script>
Because Google Consent V2 requires additional consent flags.
- Add the additional consent values. Your updated code should look like this:
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied'
});
These two lines are the additional settings:
'ad_user_data': 'denied',
'ad_personalization': 'denied',
Also, you need to add those at
<script>
function consentGrantedAdStorage() {
gtag('consent', 'update', {
'ad_user_data': 'granted'
});
gtag('consent', 'update', {
'ad_personalization': 'granted'
});
}
</script>
This is the final version of the script with Cookie Wow:
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
window.dataLayer.push(arguments);
}
// Initialize Google Analytics with default consent settings
gtag('js', new Date());
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
});
// Define wrapper to update consent if user accepts
function cwcCookieWrapper() {
if (window.cwcIsUserAccept && window.cwcIsUserAccept('analytics')) {
gtag('consent', 'update', {
'analytics_storage': 'granted'
});
}
if (window.cwcIsUserAccept && window.cwcIsUserAccept('marketing')) {
gtag('consent', 'update', {
'ad_storage': 'granted',
'ad_user_data': 'granted',
'ad_personalization': 'granted'
});
}
}
</script>
Now you can test it.
Updated on: 02/09/2025
Thank you!