Google Consent Mode v2 Default Settings
Sets Google Consent Mode defaults before any Google tag loads, denying ad and analytics storage for visitors in the EEA, UK and Switzerland until your consent tool grants it.
Opens WPIDE on
Code
add_action( 'wp_head', function () {
// Regions where storage is denied by default (ISO country codes). Empty array = everywhere.
$regions = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IS', 'IE', 'IT', 'LV', 'LI', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB', 'CH' );
$denied = array(
'ad_storage' => 'denied',
'ad_user_data' => 'denied',
'ad_personalization' => 'denied',
'analytics_storage' => 'denied',
'wait_for_update' => 500,
);
if ( $regions ) {
$denied['region'] = $regions;
}
echo "<script>\nwindow.dataLayer = window.dataLayer || [];\nfunction gtag(){dataLayer.push(arguments);}\n";
if ( $regions ) {
echo "gtag('consent', 'default', { ad_storage: 'granted', ad_user_data: 'granted', ad_personalization: 'granted', analytics_storage: 'granted' });\n";
}
echo 'gtag(\'consent\', \'default\', ' . wp_json_encode( $denied ) . ");\ngtag('set', 'ads_data_redaction', true);\n</script>\n";
}, 1 );
Notes
Your cookie banner must send the matching gtag('consent', 'update', ...) call. Edit $regions to apply the denied default elsewhere.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.