|
1 | 1 | {% if GOOGLEANALYTICS_ID %} |
| 2 | + {% if S_CONSENTMANAGER_ANALYTICS_ENABLED %} |
| 3 | + <script> |
| 4 | + window.dataLayer = window.dataLayer || []; |
| 5 | + window.gtag = window.gtag || function(){window.dataLayer.push(arguments);} |
| 6 | + |
| 7 | + window.gtag('consent', 'default', { |
| 8 | + 'analytics_storage': 'denied' |
| 9 | + }); |
| 10 | + |
| 11 | + (function(window) { |
| 12 | + function updateConsent() { |
| 13 | + window.gtag('consent', 'update', { |
| 14 | + 'analytics_storage': window.consentManager && typeof window.consentManager.hasConsent === 'function' && window.consentManager.hasConsent('analytics') ? 'granted' : 'denied' |
| 15 | + }); |
| 16 | + } |
| 17 | + |
| 18 | + if (window.consentManager && typeof window.consentManager.onChange === 'function') |
| 19 | + { |
| 20 | + window.consentManager.onChange(updateConsent); |
| 21 | + } |
| 22 | + else |
| 23 | + { |
| 24 | + updateConsent(); |
| 25 | + } |
| 26 | + })(window); |
| 27 | + </script> |
| 28 | + {% endif %} |
2 | 29 | <!-- Google tag (gtag.js) - Google Analytics --> |
3 | | - <script{% if S_CONSENTMANAGER_ANALYTICS_ENABLED %} type="text/plain" data-consent-category="analytics"{% endif %} async src="https://www.googletagmanager.com/gtag/js?id={{ GOOGLEANALYTICS_ID }}"></script> |
4 | | - <script{% if S_CONSENTMANAGER_ANALYTICS_ENABLED %} type="text/plain" data-consent-category="analytics"{% endif %}> |
| 30 | + <script async src="https://www.googletagmanager.com/gtag/js?id={{ GOOGLEANALYTICS_ID }}"></script> |
| 31 | + <script> |
5 | 32 | window.dataLayer = window.dataLayer || []; |
6 | | - function gtag(){dataLayer.push(arguments);} |
7 | | - gtag('js', new Date()); |
| 33 | + window.gtag = window.gtag || function(){window.dataLayer.push(arguments);} |
| 34 | + {% if S_CONSENTMANAGER_ANALYTICS_ENABLED %} |
| 35 | + if (window.consentManager && typeof window.consentManager.hasConsent === 'function') |
| 36 | + { |
| 37 | + window.gtag('consent', 'update', { |
| 38 | + 'analytics_storage': window.consentManager.hasConsent('analytics') ? 'granted' : 'denied' |
| 39 | + }); |
| 40 | + } |
| 41 | + {% endif %} |
| 42 | + window.gtag('js', new Date()); |
8 | 43 |
|
9 | | - gtag('config', '{{ GOOGLEANALYTICS_ID }}', { |
| 44 | + window.gtag('config', '{{ GOOGLEANALYTICS_ID }}', { |
10 | 45 | {%- EVENT phpbb_googleanalytics_gtag_options -%} |
11 | 46 | {%- if S_REGISTERED_USER %}'user_id': '{{ GOOGLEANALYTICS_USER_ID }}',{% endif -%} |
12 | 47 | {%- if S_ANONYMIZE_IP %}'anonymize_ip': true,{% endif -%} |
|
0 commit comments