From dfc568afb0b17c74ae62afd0a5bddd4b31e19654 Mon Sep 17 00:00:00 2001 From: Samuel Olwe Date: Mon, 8 Apr 2024 16:55:15 +0300 Subject: [PATCH 1/3] Add consent mode when script loads --- src/js/main.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/js/main.js b/src/js/main.js index 11d44675..8e2487ee 100755 --- a/src/js/main.js +++ b/src/js/main.js @@ -7,6 +7,9 @@ import { loadConsentFromCookie, } from "./utils.js"; +// Add Google Consent Mode as soon as the script is loaded +addGoogleConsentMode(); + export const cookiePolicy = (callback = null) => { let cookiePolicyContainer = null; let language = document.documentElement.lang; @@ -45,8 +48,6 @@ export const cookiePolicy = (callback = null) => { }; const init = function () { - // Add the default setup script for Google Consent Mode - addGoogleConsentMode(); // Load the consent from the cookie, if available loadConsentFromCookie(); From 9bca3322d3133508086f1625299a1f54cf8ed3d4 Mon Sep 17 00:00:00 2001 From: Samuel Olwe Date: Mon, 8 Apr 2024 16:55:57 +0300 Subject: [PATCH 2/3] Pass objects unstringified --- src/js/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/utils.js b/src/js/utils.js index 90d86114..4d658283 100755 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -111,7 +111,7 @@ export const addGoogleConsentMode = () => { }; // Set default consent to 'denied' as a placeholder - window.gtag("consent", "default", JSON.stringify(DEFAULT_CONSENT)); + window.gtag("consent", "default", DEFAULT_CONSENT); } }; @@ -170,7 +170,7 @@ const updateConsentPreferences = (consentObject, selectedPreference) => { const runConsentScript = (consentObject) => { // Update preferences - window.gtag("consent", "update", JSON.stringify(consentObject)); + window.gtag("consent", "update", consentObject); }; const pushPageview = () => { From dea2bf363d6d0e2362f38ee813f4270cbc91c16d Mon Sep 17 00:00:00 2001 From: Samuel Olwe Date: Mon, 8 Apr 2024 17:11:24 +0300 Subject: [PATCH 3/3] Update version to v3.6.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47c1d1d9..f32393d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@canonical/cookie-policy", - "version": "3.6.1", + "version": "3.6.2", "description": "A script and style sheet that displays a cookie policy notification", "main": "build/js/module.js", "iife": "build/js/cookie-policy.js",