# Honor Global Privacy Control Signals

> Detects visitors whose browser sends a Global Privacy Control (GPC) or Do Not Track signal and updates Google Consent Mode to deny ad storage and personalization for them.

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

## Code

```php
add_action( 'wp_head', function () {
    $deny_analytics = false; // Also deny analytics storage for GPC/DNT visitors.

    $update = array(
        'ad_storage'         => 'denied',
        'ad_user_data'       => 'denied',
        'ad_personalization' => 'denied',
    );

    if ( $deny_analytics ) {
        $update['analytics_storage'] = 'denied';
    }
    ?>
<script>
(function () {
    var optOut = navigator.globalPrivacyControl === true || navigator.doNotTrack === '1' || window.doNotTrack === '1';
    if (!optOut) { return; }
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('consent', 'update', <?php echo wp_json_encode( $update ); ?>);
    window.wpideOptOut = true;
})();
</script>
    <?php
}, 2 );
```

## Notes

Analytics storage is left to your consent banner. Set $deny_analytics to true to deny it too for these visitors.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Honor Global Privacy Control Signals" 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/
