From d8bc79ad2dfb4d70bfe64fa2f349398073b1b0a2 Mon Sep 17 00:00:00 2001 From: Frank Blechschmidt Date: Mon, 22 May 2023 15:58:05 -0700 Subject: Add support for cookie consent and with GA4 --- layouts/_default/baseof.html | 4 + layouts/partials/consent.html | 170 ++++++++++++++++++++++++++++++++++ layouts/partials/googleanalytics.html | 18 ++++ layouts/partials/head.html | 22 ++--- 4 files changed, 202 insertions(+), 12 deletions(-) create mode 100644 layouts/partials/consent.html create mode 100644 layouts/partials/googleanalytics.html diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 237c540..18ea882 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -10,5 +10,9 @@ {{- block "main" . }}{{- end }} {{- partial "footer.html" . -}} + + {{ if not .Site.IsServer }} + {{- partial "consent.html" . -}} + {{ end }} diff --git a/layouts/partials/consent.html b/layouts/partials/consent.html new file mode 100644 index 0000000..2f9181d --- /dev/null +++ b/layouts/partials/consent.html @@ -0,0 +1,170 @@ +{{/* Based on https://hugocodex.org/add-ons/cookie-consent/ */}} + + + + + + +{{ range $index, $item := .Site.Data.consent.items }} + {{ if $item.is_functional }} + + {{ end }} +{{ end }} 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 -}} + +{{- end -}} +{{- end -}} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index f01e36b..f658d68 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -10,23 +10,21 @@ - - {{ $style := resources.Get "sass/researcher.scss" | resources.ExecuteAsTemplate "sass/researcher.scss" . | toCSS | minify }} + {{ $style := resources.Get "sass/researcher.scss" | resources.ExecuteAsTemplate "sass/researcher.scss" . | toCSS | minify -}} - - {{ with .Site.Params.favicon }} - - {{ end }} + {{ with .Site.Params.favicon -}} + + {{ end -}} {{ with .OutputFormats.Get "rss" -}} {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} {{ end -}} - {{ if not .Site.IsServer }} - {{ template "_internal/google_analytics.html" . }} - {{ end }} + {{- if not .Site.IsServer -}} + {{- partial "googleanalytics.html" . -}} + {{- end -}} - {{ if .Params.noindex }} - - {{ end }} + {{ if .Params.noindex -}} + + {{ end -}} -- cgit v1.2.3