Skip to content

Commit

Permalink
Update to consent script. (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunR1991 authored Dec 12, 2024
1 parent 6821b97 commit 5e1ada5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
19 changes: 12 additions & 7 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
36 changes: 33 additions & 3 deletions public/cookieconsent-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 <a href=\"/Resources/privacy-policy\">Privacy Policy</a>.",
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 <a href=\"/resources/privacy-policy\">Privacy Policy</a>.",
acceptAllBtn: "Accept All Cookies",
acceptNecessaryBtn: "Reject Non-Essential Cookies",
showPreferencesBtn: "Manage Preferences",
Expand Down Expand Up @@ -64,7 +94,7 @@ CookieConsent.run({
},
{
title: "More Information",
description: "Please see our <a class=\"cc__link\" href=\"/Resources/privacy-policy\">privacy policy</a> for more information."
description: "Please see our <a class=\"cc__link\" href=\"/resources/privacy-policy\">privacy policy</a> for more information."
}
]
}
Expand Down

0 comments on commit 5e1ada5

Please sign in to comment.