From ccc12b974b0778b90c5e5d5cd54065aa19055a9c Mon Sep 17 00:00:00 2001 From: Massimo Maggioni <94243057+MassimoMaggioni@users.noreply.github.com> Date: Wed, 9 Feb 2022 23:12:20 +0100 Subject: [PATCH] redesign banner logic: separation from libray loading and active js code --- data/consent.yaml | 13 ------ data/gdpr.yaml | 8 ++++ layouts/partials/footer/custom.html | 6 +-- .../gdpr/{consent.html => banner.html} | 45 +++++++++++++------ layouts/partials/gdpr/gtag.html | 2 + layouts/partials/head/head.html | 4 +- static/js/gtag.js | 5 +++ 7 files changed, 51 insertions(+), 32 deletions(-) delete mode 100644 data/consent.yaml create mode 100644 data/gdpr.yaml rename layouts/partials/gdpr/{consent.html => banner.html} (84%) create mode 100644 layouts/partials/gdpr/gtag.html create mode 100644 static/js/gtag.js diff --git a/data/consent.yaml b/data/consent.yaml deleted file mode 100644 index 2ca81ad..0000000 --- a/data/consent.yaml +++ /dev/null @@ -1,13 +0,0 @@ -items: - - title: Google Anaytics (functional) - description: This code gives us insight into the number of people that visit our website, where they are from and what they are clicking on. We follow the guidelines of the Dutch Government, which describe how to use Google Analytics without requiring explicit consent. - is_functional: true - script_file: ga.js - - title: Disqus comment (functional) - description: This code gives users the option to comment the articles. - is_functional: true - script_file: disqus.js - - title: Crisp chat - description: This code gives users the option to chat directly with us through a chat box in the bottom right corner. Visitor data will (also) be sent to Crisp. - is_functional: false - script_file: crisp.js diff --git a/data/gdpr.yaml b/data/gdpr.yaml new file mode 100644 index 0000000..facbd94 --- /dev/null +++ b/data/gdpr.yaml @@ -0,0 +1,8 @@ +plugins: + - name: gtag + enabled: true + functional: false + title: Google Analytics + description: This code gives us insight into the number of people that visit our website, where they are from and what they are clicking on. We follow the guidelines of the Italian Government. + html_src: gdpr/gtag.html + js_src: js/gtag.js diff --git a/layouts/partials/footer/custom.html b/layouts/partials/footer/custom.html index d4cf7aa..37a8817 100644 --- a/layouts/partials/footer/custom.html +++ b/layouts/partials/footer/custom.html @@ -1,5 +1,3 @@ -{{ if .Site.Params.GDPRbanner.enabled }} - {{ if not .Site.Params.GDPRbanner.onlyfunctional }} - {{ partial "gdpr/consent.html" . }} - {{ end }} +{{ if and .Site.Params.GDPRbanner.enabled (not .Site.Params.GDPRbanner.onlyfunctional) }} + {{ partial "gdpr/banner.html" . }} {{ end }} diff --git a/layouts/partials/gdpr/consent.html b/layouts/partials/gdpr/banner.html similarity index 84% rename from layouts/partials/gdpr/consent.html rename to layouts/partials/gdpr/banner.html index a63f98f..9aa95f6 100644 --- a/layouts/partials/gdpr/consent.html +++ b/layouts/partials/gdpr/banner.html @@ -1,3 +1,4 @@ + + + +{{ range $index, $plugin := .Site.Data.gdpr.plugins }} + {{ if $plugin.enabled }} + {{ "" }} + {{ partial $plugin.html_src }} + {{ if $plugin.functional }} + + {{ end }} + {{ "" }} + {{ end }} +{{ end }} + + - - -{{ range $index, $item := .Site.Data.consent.items }} - {{ if $item.is_functional }} - - {{ end }} -{{ end }} diff --git a/layouts/partials/gdpr/gtag.html b/layouts/partials/gdpr/gtag.html new file mode 100644 index 0000000..22e0a2b --- /dev/null +++ b/layouts/partials/gdpr/gtag.html @@ -0,0 +1,2 @@ + + diff --git a/layouts/partials/head/head.html b/layouts/partials/head/head.html index 4d89b89..bb0f00c 100644 --- a/layouts/partials/head/head.html +++ b/layouts/partials/head/head.html @@ -21,5 +21,7 @@ {{ end }} -{{- template "_internal/google_analytics.html" . -}} +{{ if not .Site.Params.GDPRbanner.enabled }} + {{- template "_internal/google_analytics.html" . -}} +{{ end }} {{- partial "head/custom.html" . -}} diff --git a/static/js/gtag.js b/static/js/gtag.js new file mode 100644 index 0000000..2ef91de --- /dev/null +++ b/static/js/gtag.js @@ -0,0 +1,5 @@ +window.dataLayer = window.dataLayer || []; +function gtag(){window.dataLayer.push(arguments);} +gtag('js', new Date()); + +gtag('config', 'GA_MEASUREMENT_ID');