{"version":3,"file":"consent--5TwCnDJ.js","sources":["../../../../../assets/default/js/google-tag-manager/consent.js","../../../../../assets/default/js/google-tag-manager/index.js"],"sourcesContent":["import { ConsentEvents } from '../events';\n\nexport default class CookieConsent {\n #cookieConsentName = 'autowise-cookie-consent';\n #document;\n #consentForm;\n #consentDialog;\n #preferencesDialog;\n\n constructor(document, consentFormSelector, consentDialogSelector, preferencesDialogSelector) {\n this.#document = document;\n this.#consentForm = document.querySelector(consentFormSelector);\n this.#consentDialog = document.querySelector(consentDialogSelector);\n this.#preferencesDialog = document.querySelector(preferencesDialogSelector);\n\n if (this.#consentForm === null) {\n throw new Error('Consent form not found');\n }\n\n if (this.#consentDialog === null) {\n throw new Error('Consent dialog not found');\n }\n\n if (this.#preferencesDialog === null) {\n throw new Error('Preferences dialog not found');\n }\n\n this.#bindListener();\n }\n\n hasGivenConsent() {\n return this.#document.cookie.split(';').some((item) => item.trim().startsWith(this.#cookieConsentName));\n }\n\n isCookiePolicyPage() {\n const cookiePolicyLink = this.#consentDialog.querySelector('a[data-cookie-policy-link]');\n\n if (cookiePolicyLink) {\n return window.location.pathname.indexOf(cookiePolicyLink.attributes.href.value) !== -1;\n }\n\n return false;\n }\n\n load() {\n const cookie = this.#document.cookie.split(';').find((item) => item.trim().startsWith(this.#cookieConsentName));\n\n if (cookie === undefined) {\n throw new Error('Cookie not found');\n }\n\n let categories;\n\n try {\n categories = JSON.parse(decodeURIComponent(cookie.split('=')[1]));\n } catch {\n categories = this.#getCategories();\n }\n\n this.#document.dispatchEvent(\n new CustomEvent(ConsentEvents.CONSENT_UPDATED, {\n detail: {\n ...this.#getCategories(),\n ...categories,\n },\n }),\n );\n }\n\n show() {\n // Check if we are running from an embed\n if (window && window !== window.parent) {\n console.info('Consent dialog cannot be activated due to the inability to set a cookie in the parent window.');\n return;\n }\n\n this.#consentDialog.showModal();\n }\n\n acceptAll() {\n const categories = this.#getCategories();\n\n for (const category of Object.keys(categories)) {\n categories[category] = true;\n }\n\n this.#storeCookie(categories);\n this.#document.dispatchEvent(\n new CustomEvent(ConsentEvents.CONSENT_UPDATED, {\n detail: categories,\n }),\n );\n\n this.#closeModals();\n }\n\n denyAll() {\n const categories = this.#getCategories();\n\n for (const category of Object.keys(categories)) {\n categories[category] = false;\n }\n\n this.#storeCookie(categories);\n this.#document.dispatchEvent(\n new CustomEvent(ConsentEvents.CONSENT_UPDATED, {\n detail: categories,\n }),\n );\n\n this.#closeModals();\n }\n\n savePreferences() {\n const categories = this.#getCategories();\n this.#storeCookie(categories);\n this.#document.dispatchEvent(\n new CustomEvent(ConsentEvents.CONSENT_UPDATED, {\n detail: categories,\n }),\n );\n\n this.#closeModals();\n }\n\n #bindListener() {\n this.#consentForm.addEventListener('submit', (e) => {\n e.preventDefault();\n const buttonName = e.submitter.name;\n\n if (buttonName === 'accept-all') {\n this.acceptAll();\n return;\n }\n\n if (buttonName === 'deny-all') {\n this.denyAll();\n return;\n }\n\n if (buttonName === 'modify-cookie-preferences') {\n this.#preferencesDialog.showModal();\n return;\n }\n\n if (buttonName === 'save-cookie-preferences') {\n this.savePreferences();\n return;\n }\n\n throw new Error('Unknown button');\n });\n }\n\n #storeCookie(categories) {\n this.#document.cookie = `${this.#cookieConsentName}=${encodeURIComponent(\n JSON.stringify(categories),\n )}; path=/; secure; max-age=31536000; SameSite=Strict`;\n }\n\n #getCategories() {\n const categories = {};\n\n for (const input of this.#document.querySelectorAll('input[name^=\"cookie_consent[\"]')) {\n categories[input.name.match(/\\[([a-z]+)]/)[1]] = input.checked;\n }\n\n return categories;\n }\n\n #closeModals() {\n if (this.#preferencesDialog.open) {\n this.#preferencesDialog.close();\n }\n\n if (this.#consentDialog.open) {\n this.#consentDialog.close();\n }\n }\n}\n","import CookieConsent from './consent';\nimport { ConsentEvents } from '../events';\n\nwindow.dataLayer = window.dataLayer || [];\n\nconst scriptTag = document.querySelector('script[data-autowise-consent-mode][data-gtm-api-key]');\n\nfunction gtag() {\n // biome-ignore lint/style/noArguments: Recommended by Google Tag Manager\n window.dataLayer.push(arguments);\n}\n\n// Load Google Tag Manager\nfunction gtm(w, d, s, l, i) {\n w[l] = w[l] || [];\n w[l].push({\n 'gtm.start': +new Date(),\n event: 'gtm.js',\n });\n const f = d.getElementsByTagName(s)[0];\n const j = d.createElement(s);\n const dl = l !== 'dataLayer' ? `&l=${l}` : '';\n j.async = true;\n j.src = `https://www.googletagmanager.com/gtm.js?id=${i}${dl}`;\n f.parentNode.insertBefore(j, f);\n}\n\nif (!scriptTag) {\n throw new Error('Script tag not found');\n}\n\nif (scriptTag.dataset.autowiseConsentMode === 'true') {\n gtag('consent', 'default', {\n security_storage: 'granted',\n functional_storage: 'denied',\n ad_storage: 'denied',\n ad_user_data: 'denied',\n ad_personalization: 'denied',\n analytics_storage: 'denied',\n wait_for_update: 500,\n });\n\n gtag('set', 'url_passthrough', true);\n\n const consent = new CookieConsent(\n document,\n '#autowise-cookie-consent-form',\n '#autowise-cookie-consent-dialog',\n '#autowise-cookie-preferences-dialog',\n );\n\n document.addEventListener(ConsentEvents.CONSENT_UPDATED, (e) => {\n const consentCategories = e.detail;\n const grantedOrDenied = (category) => (consentCategories[category] || false ? 'granted' : 'denied');\n const analytics = grantedOrDenied('analytics');\n const marketing = grantedOrDenied('marketing');\n const functional = grantedOrDenied('functional');\n\n gtag('consent', 'update', {\n security_storage: 'granted',\n functional_storage: functional,\n ad_storage: marketing,\n ad_user_data: marketing,\n ad_personalization: marketing,\n analytics_storage: analytics,\n });\n });\n\n if (consent.hasGivenConsent()) {\n consent.load();\n } else if (!consent.isCookiePolicyPage()) {\n // Feels kinda useless to ask a customer for consent on the cookie policy page itself.\n consent.show();\n }\n}\n\ngtm(window, document, 'script', 'dataLayer', scriptTag.dataset.gtmApiKey);\n"],"names":["CookieConsent","document","consentFormSelector","consentDialogSelector","preferencesDialogSelector","__privateAdd","_CookieConsent_instances","_cookieConsentName","_document","_consentForm","_consentDialog","_preferencesDialog","__privateSet","__privateGet","__privateMethod","bindListener_fn","item","cookiePolicyLink","cookie","categories","getCategories_fn","ConsentEvents","category","storeCookie_fn","closeModals_fn","buttonName","input","scriptTag","gtag","gtm","w","d","s","l","i","f","j","dl","consent","consentCategories","grantedOrDenied","analytics","marketing","functional"],"mappings":"0zBAEe,MAAMA,CAAc,CAO/B,YAAYC,EAAUC,EAAqBC,EAAuBC,EAA2B,CAPlFC,EAAA,KAAAC,GACXD,EAAA,KAAAE,EAAqB,2BACrBF,EAAA,KAAAG,GACAH,EAAA,KAAAI,GACAJ,EAAA,KAAAK,GACAL,EAAA,KAAAM,GAQI,GALAC,EAAA,KAAKJ,EAAYP,GACjBW,EAAA,KAAKH,EAAeR,EAAS,cAAcC,CAAmB,GAC9DU,EAAA,KAAKF,EAAiBT,EAAS,cAAcE,CAAqB,GAClES,EAAA,KAAKD,EAAqBV,EAAS,cAAcG,CAAyB,GAEtES,EAAA,KAAKJ,KAAiB,KACtB,MAAM,IAAI,MAAM,wBAAwB,EAG5C,GAAII,EAAA,KAAKH,KAAmB,KACxB,MAAM,IAAI,MAAM,0BAA0B,EAG9C,GAAIG,EAAA,KAAKF,KAAuB,KAC5B,MAAM,IAAI,MAAM,8BAA8B,EAGlDG,EAAA,KAAKR,EAAAS,GAAL,UACR,CAEI,iBAAkB,CACd,OAAOF,EAAA,KAAKL,GAAU,OAAO,MAAM,GAAG,EAAE,KAAMQ,GAASA,EAAK,KAAM,EAAC,WAAWH,EAAA,KAAKN,EAAkB,CAAC,CAC9G,CAEI,oBAAqB,CACjB,MAAMU,EAAmBJ,EAAA,KAAKH,GAAe,cAAc,4BAA4B,EAEvF,OAAIO,EACO,OAAO,SAAS,SAAS,QAAQA,EAAiB,WAAW,KAAK,KAAK,IAAM,GAGjF,EACf,CAEI,MAAO,CACH,MAAMC,EAASL,EAAA,KAAKL,GAAU,OAAO,MAAM,GAAG,EAAE,KAAMQ,GAASA,EAAK,KAAI,EAAG,WAAWH,EAAA,KAAKN,EAAkB,CAAC,EAE9G,GAAIW,IAAW,OACX,M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