| @@ -92,13 +92,31 @@ | ||
| 92 | 92 | ] |
| 93 | 93 | ) |
| 94 | 94 | ); |
| 95 | 95 | $map = self::signal_map(); |
| 96 | + $ads = (bool) Helper::get( 'consent_mode_ads', true ); | |
| 96 | 97 | ?> |
| 97 | 98 | <script id="ablocks-consent-mode" data-ablocks-consent-skip="1"> |
| 98 | 99 | /* aBlocks Consent Mode v2 — must stay the first script in the document. */ |
| 99 | 100 | window.dataLayer = window.dataLayer || []; |
| 100 | 101 | function gtag(){ dataLayer.push( arguments ); } |
| 102 | +<?php if ( $ads ) : ?> | |
| 103 | + <?php | |
| 104 | + // The two settings Google pairs with denied defaults, and the reason a | |
| 105 | + // refusal need not cost the site its conversion reporting. | |
| 106 | + // | |
| 107 | + // `ads_data_redaction` strips ad identifiers from the requests Google Ads | |
| 108 | + // still makes while `ad_storage` is denied. `url_passthrough` carries the | |
| 109 | + // click id in the URL between pages instead of a cookie, so a visitor who | |
| 110 | + // refused is still attributed to the ad they arrived from. | |
| 111 | + // | |
| 112 | + // Both are `set` calls, not consent signals: they have to be in place | |
| 113 | + // before the first tag reads them, which is why they sit here rather than | |
| 114 | + // in the update the banner sends. | |
| 115 | + ?> | |
| 116 | +gtag( 'set', 'ads_data_redaction', true ); | |
| 117 | +gtag( 'set', 'url_passthrough', true ); | |
| 118 | +<?php endif; ?> | |
| 101 | 119 | gtag( 'consent', 'default', <?php echo wp_json_encode( $defaults ); ?> ); |
| 102 | 120 | ( function () { |
| 103 | 121 | var names = <?php echo wp_json_encode( $cookies ); ?>; |
| 104 | 122 | var map = <?php echo wp_json_encode( $map ); ?>; |
| @@ -119,8 +137,12 @@ | ||
| 119 | 137 | var state = granted.indexOf( category ) > -1 ? 'granted' : 'denied'; |
| 120 | 138 | map[ category ].forEach( function ( signal ) { update[ signal ] = state; } ); |
| 121 | 139 | } ); |
| 122 | 140 | gtag( 'consent', 'update', update ); |
| 141 | + <?php if ( $ads ) : ?> | |
| 142 | + <?php // Redaction is only wanted while ads are refused; leaving it on after a grant would quietly degrade the reporting the visitor agreed to. ?> | |
| 143 | + if ( 'granted' === update.ad_storage ) { gtag( 'set', 'ads_data_redaction', false ); } | |
| 144 | + <?php endif; ?> | |
| 123 | 145 | <?php // Recorded so the main script does not send the same state a second time on every page view of a visitor who already decided. ?> |
| 124 | 146 | window.ABlocksConsentSignals = update; |
| 125 | 147 | } )(); |
| 126 | 148 | </script> |