google-consent-mode-js.php
36 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @var string $data_layer |
| 4 | * @var string $url_passthrough |
| 5 | * @var bool|string $consent_attribute |
| 6 | * @var string $script_type |
| 7 | */ |
| 8 | |
| 9 | ?> |
| 10 | <script type="<?php echo esc_attr( $script_type ); ?>"<?php echo ! $consent_attribute ? '' : ' data-cookieconsent="' . esc_attr( $consent_attribute ) . '"'; ?>> |
| 11 | window.<?php echo esc_js( $data_layer ); ?> = window.<?php echo esc_js( $data_layer ); ?> || []; |
| 12 | |
| 13 | function gtag() { |
| 14 | <?php echo esc_js( $data_layer ); ?>. |
| 15 | push(arguments); |
| 16 | } |
| 17 | |
| 18 | gtag("consent", "default", { |
| 19 | ad_user_data: "denied", |
| 20 | ad_personalization: "denied", |
| 21 | ad_storage: "denied", |
| 22 | analytics_storage: "denied", |
| 23 | functionality_storage: "denied", |
| 24 | personalization_storage: "denied", |
| 25 | security_storage: "granted", |
| 26 | wait_for_update: 500, |
| 27 | }); |
| 28 | gtag("set", "ads_data_redaction", true); |
| 29 | <?php |
| 30 | if ( $url_passthrough ) { |
| 31 | echo /** @lang JavaScript */ |
| 32 | 'gtag("set", "url_passthrough", true);' . PHP_EOL; |
| 33 | } |
| 34 | ?> |
| 35 | </script> |
| 36 |