Skip to content

Commit

Permalink
fix(cookie-consent): handle breaking changes from 3.0.0 bump
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mulier-p committed Mar 14, 2024
1 parent 9931c26 commit 742b573
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 82 deletions.
57 changes: 45 additions & 12 deletions assets/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -452,27 +452,60 @@ blockquote.blockquote {
}

:root{
--spacer: #{$spacer};
}

#cc-main {
--cc-font-family: var(--bs-body-font-family);
--cc-bg: var(--bs-body-bg);
--cc-z-index: 2147483647;
--cc-text: var(--bs-body-color);
--cc-border-radius: var(--bs-border-radius-lg);
--cc-primary-color: var(--bs-body-color);
--cc-secondary-color: var(--bs-body-color);
--cc-modal-border-radius: var(--bs-border-radius-lg);
--cc-btn-primary-bg: var(--bs-primary);
--cc-btn-primary-hover-bg: var(--bs-primary-text-emphasis);
--cc-btn-secondary-bg: var(--bs-gray-300);
--cc-btn-secondary-text: var(--bs-body-color);
--cc-btn-secondary-hover-bg: var(--bs-gray-400);
--cc-btn-border-radius: var(--bs-border-radius);
--cc-toggle-bg-off: var(--bs-gray-600);
--cc-toggle-bg-readonly: var(--bs-gray-300);
--cc-toggle-on-bg: var(--cc-btn-primary-bg);
--cc-toggle-off-bg: var(--bs-gray-600);
--cc-toggle-readonly-bg: var(--bs-gray-300);
--cc-cookie-category-block-bg: var(--bs-gray-200);
--cc-cookie-category-block-bg-hover: var(--bs-gray-300);
--cc-section-border: var(--bs-border-color);
--cc-cookie-table-border: var(--bs-border-color);
--cc-cookie-category-block-hover-bg: var(--bs-gray-300);
--cc-section-category-border: var(--bs-border-color);
--cc-cookie-category-block-border: var(--bs-border-color);
--cc-overlay-bg: var(--bs-black);
--cc-overlay-opacity: .5;
--cc-consent-modal-box-shadow: var(--bs-box-shadow-lg);
--spacer: #{$spacer};

.cc--anim {
.pm-wrapper .pm-overlay, .cm-wrapper:before {
opacity: .5 !important;
}
}

.cc-link {
&, &:hover {
color: var(--cc-btn-primary-bg);
}
}

.cm__desc {
color: inherit;
}

.cm {
box-shadow: var(--bs-box-shadow-lg);
}

.pm button[data-role="necessary"]{
background-color: var(--cc-btn-secondary-bg);
border-color: var(--cc-btn-secondary-border-color);
color: var(--cc-btn-secondary-color);

&:hover {
background: var(--cc-btn-secondary-hover-bg);
border-color: var(--cc-btn-secondary-hover-border-color);
color: var(--cc-btn-secondary-hover-color);
}
}
}

.medium-zoom-overlay {
Expand Down
130 changes: 60 additions & 70 deletions plugins/cookieconsent.client.ts
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', () => {
Expand Down Expand Up @@ -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>.',
}
]
]
}
}
}
}
Expand Down

0 comments on commit 742b573

Please sign in to comment.