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.
Opens WPIDE on
Code
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 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.