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", 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(); 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 = () => {