Merged in fix/consent (pull request #61)
Fix/consent Approved-by: Michael Zetterberg
This commit is contained in:
@@ -22,6 +22,7 @@ export default function RootLayout({
|
||||
src="/_static/dist/js/cookie-bot.js?1705409331007"
|
||||
/>
|
||||
<Script
|
||||
strategy="beforeInteractive"
|
||||
data-blockingmode="auto"
|
||||
data-cbid="6d539de8-3e67-4f0f-a0df-8cef9070f712"
|
||||
data-culture="@cultureCode"
|
||||
|
||||
@@ -29,6 +29,7 @@ export default function RootLayout({
|
||||
src="/_static/dist/js/cookie-bot.js?1705409331007"
|
||||
/>
|
||||
<Script
|
||||
strategy="beforeInteractive"
|
||||
data-blockingmode="auto"
|
||||
data-cbid="6d539de8-3e67-4f0f-a0df-8cef9070f712"
|
||||
data-culture="@cultureCode"
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
TrackingProps,
|
||||
} from "@/types/components/tracking"
|
||||
import { usePathname, useSearchParams } from "next/navigation"
|
||||
import { useEffect } from "react"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
function createPageObject(trackingData: TrackingData) {
|
||||
const [lang, ...segments] = trackingData.pathName
|
||||
@@ -65,6 +65,27 @@ export default function Tracking({ pageData }: TrackingProps) {
|
||||
const pathName = usePathname()
|
||||
const queryString = useSearchParams().toString()
|
||||
|
||||
function CookiebotCallbackOnAccept() {
|
||||
const cookie = window._satellite.cookie.get("CookieConsent")
|
||||
|
||||
if (window.Cookiebot?.changed && window.adobe) {
|
||||
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"))
|
||||
}
|
||||
}
|
||||
|
||||
function CookebotCallbackOnDecline() {
|
||||
if (window.Cookiebot?.changed && window.adobe) {
|
||||
window.adobe.optIn.deny(window.adobe.OptInCategories.ANALYTICS, true)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (window.datalayer) {
|
||||
const trackingData = { ...pageData, pathName, queryString }
|
||||
@@ -76,29 +97,16 @@ export default function Tracking({ pageData }: TrackingProps) {
|
||||
|
||||
useEffect(() => {
|
||||
// handle consent
|
||||
window.addEventListener(
|
||||
"CookiebotOnAccept",
|
||||
function CookiebotCallback_OnAccept(e) {
|
||||
if (window.Cookiebot?.changed && window.adobe) {
|
||||
if (
|
||||
window._satellite.cookie
|
||||
.get("CookieConsent")
|
||||
.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()
|
||||
}
|
||||
}
|
||||
)
|
||||
window.addEventListener("CookiebotOnAccept", CookiebotCallbackOnAccept)
|
||||
window.addEventListener("CookiebotOnDecline", CookebotCallbackOnDecline)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("CookiebotOnAccept", CookiebotCallbackOnAccept)
|
||||
window.removeEventListener(
|
||||
"CookiebotOnDecline",
|
||||
CookebotCallbackOnDecline
|
||||
)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return null
|
||||
|
||||
8
public/_static/dist/js/cookie-bot.js
vendored
8
public/_static/dist/js/cookie-bot.js
vendored
@@ -73,10 +73,4 @@ window.addEventListener("load", (function() {
|
||||
e.text = "Muuta hyväksyntäsi",
|
||||
t.text = "Peru hyväksyntäsi"
|
||||
}
|
||||
}
|
||||
)),
|
||||
window.addEventListener("CookiebotOnAccept", (function(e) {
|
||||
window.Cookiebot.changed && adobe && (window.Cookiebot.consent.statistics ? adobe.optIn.approve(adobe.OptInCategories.ANALYTICS, !0) : adobe.optIn.deny(adobe.OptInCategories.ANALYTICS, !0),
|
||||
adobe.optIn.complete())
|
||||
}
|
||||
));
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user