Skip to content

Commit

Permalink
fire scripts on banner click
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashdoughty committed Oct 30, 2019
1 parent 177e8e2 commit 484303f
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/cookieconsent.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ function isValidVersion() {
return currentVersion === null ? null : currentVersion >= COOKIE_VERSION;
}

export function getConsentSetting(key) {
const cookie = getConsent();
// double ! to convert truthy/falsy values into true/false
return !!cookie[key];
}

export function setConsentSetting(key, value) {
if (!value) {
deleteCookies();
}
// double ! to convert truthy/falsy values into true/false
setConsent({ [key]: !!value });
}

function enableScriptsAndIframes() {
const allCategories = ['preferences', 'statistics', 'marketing'];
// Filter out categories that do not have user consent
const allowedCategories = allCategories.filter(category => getConsentSetting(category) === true);

enableScriptsByCategories(allowedCategories);
enableIframesByCategories(allowedCategories);
}

// If consent is given, change the value of the cookie
function acceptConsent() {
setConsent({
Expand All @@ -142,23 +165,9 @@ function acceptAnalyticsConsent() {
necessary: true,
preferences: true,
statistics: true,
marketing: true,
consented: true,
});
}

export function getConsentSetting(key) {
const cookie = getConsent();
// double ! to convert truthy/falsy values into true/false
return !!cookie[key];
}

export function setConsentSetting(key, value) {
if (!value) {
deleteCookies();
}
// double ! to convert truthy/falsy values into true/false
setConsent({ [key]: !!value });
enableScriptsAndIframes();
}

/**
Expand Down Expand Up @@ -228,10 +237,5 @@ export function onload() {
setConsent(defaultConsent, COOKIE_TYPE.SESSION);
}

const allCategories = ['preferences', 'statistics', 'marketing'];
// Filter out categories that do not have user consent
const allowedCategories = allCategories.filter(category => getConsentSetting(category) === true);

enableScriptsByCategories(allowedCategories);
enableIframesByCategories(allowedCategories);
enableScriptsAndIframes();
}

0 comments on commit 484303f

Please sign in to comment.