Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load consent mode with script #174

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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 = () => {
Expand Down