fix: inline stack theme
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
{{- if not site.Config.Privacy.GoogleAnalytics.Disable -}}
|
||||
{{- with site.Config.Services.GoogleAnalytics.ID -}}
|
||||
{{- if strings.HasPrefix (lower .) "ua-" -}}
|
||||
{{- warnf "Google Analytics 4 (GA4) replaced Google Universal Analytics (UA) effective 1 July 2023. See https://support.google.com/analytics/answer/11583528. Create a GA4 property and data stream, then replace the Google Analytics ID in your site configuration with the new value." -}}
|
||||
{{- else -}}
|
||||
{{/* Consent-gated Google Analytics - only loads after analytics consent */}}
|
||||
<script>
|
||||
(function() {
|
||||
var gaId = {{ . }};
|
||||
var loaded = false;
|
||||
var respectDNT = {{ site.Config.Privacy.GoogleAnalytics.RespectDoNotTrack }};
|
||||
|
||||
function loadGA() {
|
||||
if (loaded) return;
|
||||
|
||||
// Respect Do Not Track browser setting if configured
|
||||
if (respectDNT) {
|
||||
var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);
|
||||
if (dnt == "1" || dnt == "yes") {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
var script = document.createElement('script');
|
||||
script.async = true;
|
||||
script.src = 'https://www.googletagmanager.com/gtag/js?id=' + gaId;
|
||||
document.head.appendChild(script);
|
||||
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', gaId);
|
||||
}
|
||||
|
||||
window.addEventListener('onCookieConsentChange', function(e) {
|
||||
if (e.detail && e.detail.analytics) {
|
||||
loadGA();
|
||||
}
|
||||
});
|
||||
|
||||
if (window.cookieConsent && window.cookieConsent.hasConsent('analytics')) {
|
||||
loadGA();
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user