-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cookie-consent): handle breaking changes from 3.0.0 bump
- Loading branch information
1 parent
9931c26
commit 742b573
Showing
2 changed files
with
105 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import 'vanilla-cookieconsent' | ||
import * as CookieConsent from "vanilla-cookieconsent"; | ||
import posthog from 'posthog-js' | ||
import axios from "axios"; | ||
|
||
export default defineNuxtPlugin(nuxtApp => { | ||
let isProd = process.env.NODE_ENV === "production"; | ||
const isEurope = Intl.DateTimeFormat().resolvedOptions().timeZone.indexOf("Europe") === 0; | ||
|
||
nuxtApp.hook('page:finish', () => { | ||
|
@@ -37,88 +36,79 @@ export default defineNuxtPlugin(nuxtApp => { | |
}; | ||
|
||
|
||
const cookieConsent = CookieConsent; | ||
nuxtApp.provide("cookieConsent", cookieConsent); | ||
const enabledMarketing = () => { | ||
cookieConsent.loadScript('https://js-eu1.hs-scripts.com/27220195.js', () => {}, [{name: "defer", value: "defer"}]); | ||
return cookieConsent.loadScript('https://js-eu1.hs-scripts.com/27220195.js',{defer: "defer"}); | ||
}; | ||
|
||
const cookieConsent = window.initCookieConsent() | ||
|
||
if (!isEurope) { | ||
enabledAnalytics(); | ||
enabledMarketing(); | ||
|
||
return; | ||
} | ||
|
||
// @ts-ignore | ||
cookieConsent.run({ | ||
autorun: true, | ||
current_lang: 'en', | ||
autoclear_cookies: false, | ||
gui_options: { | ||
consent_modal: { | ||
swap_buttons: true | ||
mode: isEurope ? 'opt-in' : 'opt-out', | ||
manageScriptTags: true, | ||
disablePageInteraction: true, | ||
guiOptions: { | ||
consentModal: { | ||
layout: 'box inline', | ||
flipButtons: true | ||
} | ||
}, | ||
page_scripts: true, | ||
force_consent: true, | ||
onAccept: () => { | ||
if (cookieConsent.allowedCategory('analytics')) { | ||
autoClearCookies: false, | ||
onConsent: ({cookie}) => { | ||
let consentCategories = cookie.categories; | ||
if (consentCategories.includes('analytics')) { | ||
enabledAnalytics(); | ||
} | ||
|
||
if (cookieConsent.allowedCategory('marketing')) { | ||
if (consentCategories.includes('marketing')) { | ||
enabledMarketing(); | ||
} | ||
}, | ||
|
||
languages: { | ||
en: { | ||
consent_modal: { | ||
title: 'I use cookies', | ||
description: 'Hi, this website uses analytics & marketing cookies to understand how you interact with it to continuously improve your user experience. <a aria-label="Cookie policy" class="cc-link" href="/cookie-policy">Read more</a>', | ||
primary_btn: { | ||
text: 'Accept', | ||
role: 'accept_all' // 'accept_selected' or 'accept_all' | ||
}, | ||
secondary_btn: { | ||
text: 'Settings', | ||
role: 'settings' // 'settings' or 'accept_necessary' | ||
categories: { | ||
analytics: { | ||
enabled: true, | ||
readOnly: false, | ||
}, | ||
marketing: { | ||
enabled: true, | ||
readOnly: false, | ||
} | ||
}, | ||
language: { | ||
default: 'en', | ||
translations: { | ||
en: { | ||
consentModal: { | ||
title: 'I use cookies', | ||
description: 'Hi, this website uses analytics & marketing cookies to understand how you interact with it to continuously improve your user experience. <a aria-label="Cookie policy" class="cc-link" href="/cookie-policy">Read more</a>', | ||
acceptAllBtn: 'Accept', | ||
showPreferencesBtn: 'Settings' | ||
}, | ||
}, | ||
settings_modal: { | ||
title: 'Cookie preferences', | ||
save_settings_btn: 'Save settings', | ||
accept_all_btn: 'Accept all', | ||
reject_all_btn: 'Reject all', | ||
blocks: [ | ||
{ | ||
title: 'Cookie usage', | ||
description: 'I use cookies to enhance your online experience. You can choose for each category to opt-in/out whenever you want.' | ||
}, | ||
{ | ||
title: 'Analytics cookies', | ||
description: 'These cookies collect information about how you use the website, which pages you visited and which links you clicked on. All of the data is anonymized and cannot be used to identify you.', | ||
toggle: { | ||
value: 'analytics', | ||
enabled: true, | ||
readonly: false | ||
} | ||
}, | ||
{ | ||
title: 'Marketing cookies', | ||
description: 'These cookies tracks your activities on our site to allow commercials to eventually reach out.', | ||
toggle: { | ||
value: 'marketing', | ||
enabled: true, | ||
readonly: false | ||
preferencesModal: { | ||
title: 'Cookie preferences', | ||
savePreferencesBtn: 'Save settings', | ||
acceptAllBtn: 'Accept all', | ||
acceptNecessaryBtn: 'Reject all', | ||
sections: [ | ||
{ | ||
title: 'Cookie usage', | ||
description: 'I use cookies to enhance your online experience. You can choose for each category to opt-in/out whenever you want.' | ||
}, | ||
{ | ||
title: 'Analytics cookies', | ||
description: 'These cookies collect information about how you use the website, which pages you visited and which links you clicked on. All of the data is anonymized and cannot be used to identify you.', | ||
linkedCategory: 'analytics', | ||
}, | ||
{ | ||
title: 'Marketing cookies', | ||
description: 'These cookies tracks your activities on our site to allow commercials to eventually reach out.', | ||
linkedCategory: 'marketing' | ||
}, | ||
{ | ||
title: 'More information', | ||
description: 'For any queries in relation to our policy on cookies and your choices, please <a class="cc-link" href="mailto:[email protected]">contact us</a>.', | ||
} | ||
}, | ||
{ | ||
title: 'More information', | ||
description: 'For any queries in relation to our policy on cookies and your choices, please <a class="cc-link" href="mailto:[email protected]">contact us</a>.', | ||
} | ||
] | ||
] | ||
} | ||
} | ||
} | ||
} | ||
|