From 3bf95eb5ad8fcfa08293c82bad075e60851155b5 Mon Sep 17 00:00:00 2001 From: Dan <49373281+HleinaD@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:38:12 +0100 Subject: [PATCH] Edits to make cookies optional v1 --- _config.yml | 2 +- _includes/analytics.js | 27 ++++++++++++++++ _includes/cookie-consent.html | 58 +++++++++++++++++++++++++++++++++++ _includes/head.html | 3 +- 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 _includes/analytics.js create mode 100644 _includes/cookie-consent.html diff --git a/_config.yml b/_config.yml index 84f1be2..77e0b68 100644 --- a/_config.yml +++ b/_config.yml @@ -134,7 +134,7 @@ footer-link-col: "#404040" #gtag: "" # Fill in your Google Analytics ID to track your website using Google Analytics -google_analytics: "UA-125339405-1" +google_analytics: "UA-125339405-1" #MUST ALSO BE UPDATED IN analytics.js # Google Tag Manager ID #gtm: "" diff --git a/_includes/analytics.js b/_includes/analytics.js new file mode 100644 index 0000000..77a7ae2 --- /dev/null +++ b/_includes/analytics.js @@ -0,0 +1,27 @@ +/*This function will load script and call the callback once the script has loaded*/ + +function loadScriptAsync(scriptSrc, callback) { +if (typeof callback !== 'function') { + throw new Error('Not a valid callback for async script load'); +} +var script = document.createElement('script'); +script.onload = callback; +script.src = scriptSrc; +document.head.appendChild(script); } + +/* This is the part where you call the above defined function and "calls back" your code which gets executed after the script has loaded */ + +// loadScriptAsync('https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX', function () { +// window.dataLayer = window.dataLayer || []; +// function gtag() { dataLayer.push(arguments); } +// gtag('js', new Date()); +// gtag('config', 'G-XXXXXXXXXX', { 'anonymize_ip': true }); +// }) + +window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; +ga('create', 'UA-125339405-1', 'auto'); +ga('send', 'pageview'); + +loadScriptAsync(src='https://www.google-analytics.com/analytics.js') + + diff --git a/_includes/cookie-consent.html b/_includes/cookie-consent.html new file mode 100644 index 0000000..2f4b344 --- /dev/null +++ b/_includes/cookie-consent.html @@ -0,0 +1,58 @@ + +