From 5e1ada5267d854018ef1c9cb1c3eba9d4724a33e Mon Sep 17 00:00:00 2001
From: ShaunR1991 <49942544+ShaunR1991@users.noreply.github.com>
Date: Thu, 12 Dec 2024 20:08:37 +1100
Subject: [PATCH] Update to consent script. (#126)
---
astro.config.mjs | 19 +++++++++++-------
public/cookieconsent-config.js | 36 +++++++++++++++++++++++++++++++---
2 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/astro.config.mjs b/astro.config.mjs
index df2fd219..c2e65745 100644
--- a/astro.config.mjs
+++ b/astro.config.mjs
@@ -28,13 +28,18 @@ export default defineConfig({
{
tag: 'script',
type: 'text/partytown',
- innerHTML:
- `window.dataLayer = window.dataLayer || [];
- function gtag() {
- dataLayer.push(arguments);
- }
- gtag("js", new Date());
- gtag("config", "G-D62C4YT9KZ");`,
+ innerHTML: `
+ window.dataLayer = window.dataLayer || [];
+ function gtag() { dataLayer.push(arguments); }
+ gtag('js', new Date());
+ gtag('consent', 'default', {
+ ad_storage: 'denied',
+ ad_user_data: 'denied',
+ ad_personalization: 'denied',
+ analytics_storage: 'denied',
+ });
+ gtag('config', 'G-D62C4YT9KZ');
+ `,
},
// CookieConsent stylesheet
{
diff --git a/public/cookieconsent-config.js b/public/cookieconsent-config.js
index 4cc78a8a..94d0827a 100644
--- a/public/cookieconsent-config.js
+++ b/public/cookieconsent-config.js
@@ -22,7 +22,37 @@ CookieConsent.run({
necessary: {
readOnly: true
},
- analytics: {},
+ analytics: {
+ services: {
+ ga4: {
+ label: 'Google Analytics 4',
+ onAccept: () => {
+ console.log("Analytics consent granted");
+ window.gtag('consent', 'update', {
+ ad_storage: 'granted',
+ ad_user_data: 'granted',
+ ad_personalization: 'granted',
+ analytics_storage: 'granted',
+ });
+ },
+ onReject: () => {
+ console.log("Analytics consent denied");
+ window.gtag('consent', 'update', {
+ ad_storage: 'denied',
+ ad_user_data: 'denied',
+ ad_personalization: 'denied',
+ analytics_storage: 'denied',
+ });
+ },
+ cookies: [
+ {
+ name: /^_ga/,
+ path: '/',
+ },
+ ],
+ },
+ },
+ },
marketing: {}
},
language: {
@@ -32,7 +62,7 @@ CookieConsent.run({
en: {
consentModal: {
title: "Your Privacy Matters to Us",
- description: "We use cookies to enhance your experience and gather anonymised analytics data to improve our website. We are a non-profit open-source project and will never use your data for advertising or sell it to third parties. For more details, see our Privacy Policy.",
+ description: "We use cookies to enhance your experience and gather anonymised analytics data to improve our website. We are a non-profit open-source project and will never use your data for advertising or sell it to third parties. For more details, see our Privacy Policy.",
acceptAllBtn: "Accept All Cookies",
acceptNecessaryBtn: "Reject Non-Essential Cookies",
showPreferencesBtn: "Manage Preferences",
@@ -64,7 +94,7 @@ CookieConsent.run({
},
{
title: "More Information",
- description: "Please see our privacy policy for more information."
+ description: "Please see our privacy policy for more information."
}
]
}