mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2025-07-29 23:00:08 +02:00

Implement React cookie banner on project dashboard GitOrigin-RevId: 95d2778d7ce7cb3054a06b06486b815a3453a623
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import getMeta from '@/utils/meta'
|
|
|
|
export type CookieConsentValue = 'all' | 'essential'
|
|
|
|
function loadGA() {
|
|
if (window.olLoadGA) {
|
|
window.olLoadGA()
|
|
}
|
|
}
|
|
|
|
export function setConsent(value: CookieConsentValue | null) {
|
|
const cookieDomain = getMeta('ol-ExposedSettings').cookieDomain
|
|
const oneYearInSeconds = 60 * 60 * 24 * 365
|
|
const cookieAttributes =
|
|
'; path=/' +
|
|
'; domain=' +
|
|
cookieDomain +
|
|
'; max-age=' +
|
|
oneYearInSeconds +
|
|
'; SameSite=Lax; Secure'
|
|
if (value === 'all') {
|
|
document.cookie = 'oa=1' + cookieAttributes
|
|
loadGA()
|
|
window.dispatchEvent(new CustomEvent('cookie-consent', { detail: true }))
|
|
} else {
|
|
document.cookie = 'oa=0' + cookieAttributes
|
|
window.dispatchEvent(new CustomEvent('cookie-consent', { detail: false }))
|
|
}
|
|
}
|
|
|
|
export function cookieBannerRequired() {
|
|
const exposedSettings = getMeta('ol-ExposedSettings')
|
|
return Boolean(
|
|
exposedSettings.gaToken ||
|
|
exposedSettings.gaTokenV4 ||
|
|
exposedSettings.propensityId ||
|
|
exposedSettings.hotjarId
|
|
)
|
|
}
|
|
|
|
export function hasMadeCookieChoice() {
|
|
return document.cookie.split('; ').some(c => c.startsWith('oa='))
|
|
}
|