# 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.

- Type: PHP
- Runs: Frontend only
- Category: [Analytics & Tracking](https://wpide.com/library/category/analytics/)
- Tags: consent, google, gdpr, gtag
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/analytics-consent-mode-defaults/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Google Consent Mode v2 Default Settings" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
