This commit is contained in:
Linus Flood
2024-10-03 15:16:56 +02:00
parent b047e31990
commit e29dff1874
10 changed files with 77 additions and 87 deletions

View File

@@ -0,0 +1,50 @@
"use client"
import { usePathname } from "next/navigation"
import { useCallback, useEffect } from "react"
import { webviews } from "@/constants/routes/webviews"
export default function CookieBot() {
const pathName = usePathname()
const isWebview = webviews.includes(pathName)
const CookiebotCallbackOnAccept = useCallback(() => {
const cookie = window._satellite.cookie.get("CookieConsent")
if (window.Cookiebot?.changed && window.adobe) {
// For webviews we always set the consent to true since we don't have cookiebot.
if (isWebview) {
window.adobe.optIn.approve(window.adobe.OptInCategories.ANALYTICS, true)
} else if (cookie?.includes("statistics:true")) {
window.adobe.optIn.approve(window.adobe.OptInCategories.ANALYTICS, true)
} else {
window.adobe.optIn.deny(window.adobe.OptInCategories.ANALYTICS, true)
}
window.adobe.optIn.complete()
console.warn("window.load event explicitly dispatched.")
window.dispatchEvent(new Event("load"))
}
}, [isWebview])
function CookebotCallbackOnDecline() {
if (window.Cookiebot?.changed && window.adobe) {
window.adobe.optIn.deny(window.adobe.OptInCategories.ANALYTICS, true)
}
}
useEffect(() => {
// handle consent
window.addEventListener("CookiebotOnAccept", CookiebotCallbackOnAccept)
window.addEventListener("CookiebotOnDecline", CookebotCallbackOnDecline)
return () => {
window.removeEventListener("CookiebotOnAccept", CookiebotCallbackOnAccept)
window.removeEventListener(
"CookiebotOnDecline",
CookebotCallbackOnDecline
)
}
}, [CookiebotCallbackOnAccept])
return null
}