mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
76beba4393
* Add cookie banner Co-authored-by: Alf Eaton <alf.eaton@overleaf.com> Co-authored-by: Miguel Serrano <mserranom@users.noreply.github.com> GitOrigin-RevId: a3625d4e6357ff58c7c47532901c382bedbe07e0
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
function loadGA() {
|
|
if (window.olLoadGA) {
|
|
window.olLoadGA()
|
|
}
|
|
}
|
|
|
|
function setConsent(value) {
|
|
document.querySelector('.cookie-banner').classList.add('hidden')
|
|
const cookieDomain = window.ExposedSettings.cookieDomain
|
|
const oneYearInSeconds = 60 * 60 * 24 * 365
|
|
const cookieAttributes =
|
|
'; domain=' +
|
|
cookieDomain +
|
|
'; max-age=' +
|
|
oneYearInSeconds +
|
|
'; SameSite=Lax; Secure'
|
|
if (value === 'all') {
|
|
document.cookie = 'oa=1' + cookieAttributes
|
|
loadGA()
|
|
} else {
|
|
document.cookie = 'oa=0' + cookieAttributes
|
|
}
|
|
}
|
|
|
|
if (window.ExposedSettings.gaToken || window.ExposedSettings.gaTokenV4) {
|
|
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')
|
|
}
|
|
}
|
|
}
|