2024-06-18 06:01:37 -04:00
|
|
|
import getMeta from '@/utils/meta'
|
|
|
|
|
2022-03-29 08:12:10 -04:00
|
|
|
function loadGA() {
|
|
|
|
if (window.olLoadGA) {
|
|
|
|
window.olLoadGA()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setConsent(value) {
|
|
|
|
document.querySelector('.cookie-banner').classList.add('hidden')
|
2024-06-18 06:01:37 -04:00
|
|
|
const cookieDomain = getMeta('ol-ExposedSettings').cookieDomain
|
2022-03-29 08:12:10 -04:00
|
|
|
const oneYearInSeconds = 60 * 60 * 24 * 365
|
|
|
|
const cookieAttributes =
|
2024-02-01 10:03:57 -05:00
|
|
|
'; path=/' +
|
2022-03-29 08:12:10 -04:00
|
|
|
'; domain=' +
|
|
|
|
cookieDomain +
|
|
|
|
'; max-age=' +
|
|
|
|
oneYearInSeconds +
|
|
|
|
'; SameSite=Lax; Secure'
|
|
|
|
if (value === 'all') {
|
|
|
|
document.cookie = 'oa=1' + cookieAttributes
|
|
|
|
loadGA()
|
2024-10-11 04:35:08 -04:00
|
|
|
window.dispatchEvent(new CustomEvent('cookie-consent', { detail: true }))
|
2022-03-29 08:12:10 -04:00
|
|
|
} else {
|
|
|
|
document.cookie = 'oa=0' + cookieAttributes
|
2024-10-11 04:35:08 -04:00
|
|
|
window.dispatchEvent(new CustomEvent('cookie-consent', { detail: false }))
|
2022-03-29 08:12:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 06:01:37 -04:00
|
|
|
if (
|
|
|
|
getMeta('ol-ExposedSettings').gaToken ||
|
|
|
|
getMeta('ol-ExposedSettings').gaTokenV4
|
|
|
|
) {
|
2022-03-29 08:12:10 -04:00
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-cookie-banner-set-consent]')
|
|
|
|
.forEach(el => {
|
|
|
|
el.addEventListener('click', function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
const consentType = el.getAttribute('data-ol-cookie-banner-set-consent')
|
|
|
|
setConsent(consentType)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
const oaCookie = document.cookie.split('; ').find(c => c.startsWith('oa='))
|
|
|
|
if (!oaCookie) {
|
|
|
|
const cookieBannerEl = document.querySelector('.cookie-banner')
|
|
|
|
if (cookieBannerEl) {
|
|
|
|
cookieBannerEl.classList.remove('hidden')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|