aboutsummaryrefslogtreecommitdiff
path: root/layouts/partials/googleanalytics.html
diff options
context:
space:
mode:
authorOlivier Roques <ojroques@users.noreply.github.com>2023-05-23 21:22:24 +0200
committerGitHub <noreply@github.com>2023-05-23 21:22:24 +0200
commit2fedeefb4506d0a6f6fd3f6629bd1ce0b09805be (patch)
tree4e98671141097ebd2f19f8e6cbb0bac83af3af92 /layouts/partials/googleanalytics.html
parentbbc9b60f3ac541d1661f7447e1568d76c419d4f9 (diff)
parent602e533fb26a941078db16921e8400853ba94d30 (diff)
Merge pull request #34 from FraBle/master
Add support for cookie consent with Google Analytics 4
Diffstat (limited to 'layouts/partials/googleanalytics.html')
-rw-r--r--layouts/partials/googleanalytics.html18
1 files changed, 18 insertions, 0 deletions
diff --git a/layouts/partials/googleanalytics.html b/layouts/partials/googleanalytics.html
new file mode 100644
index 0000000..2d72d71
--- /dev/null
+++ b/layouts/partials/googleanalytics.html
@@ -0,0 +1,18 @@
+{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
+{{- if not $pc.Disable }}{{ with .Site.GoogleAnalytics -}}
+<script>
+{{- if not $pc.RespectDoNotTrack -}}
+var doNotTrack = false;
+{{- else -}}
+var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);
+var doNotTrack = (dnt == "1" || dnt == "yes");
+{{- end -}}
+if (!doNotTrack) {
+ window.dataLayer = window.dataLayer || [];
+ function gtag(){dataLayer.push(arguments);}
+ gtag('js', new Date());
+ gtag('config', '{{ site.Config.Services.GoogleAnalytics.ID }}');
+}
+</script>
+{{- end -}}
+{{- end -}}