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"
|
src="/_static/dist/js/cookie-bot.js?1705409331007"
|
||||||
/>
|
/>
|
||||||
<Script
|
<Script
|
||||||
|
strategy="beforeInteractive"
|
||||||
data-blockingmode="auto"
|
data-blockingmode="auto"
|
||||||
data-cbid="6d539de8-3e67-4f0f-a0df-8cef9070f712"
|
data-cbid="6d539de8-3e67-4f0f-a0df-8cef9070f712"
|
||||||
data-culture="@cultureCode"
|
data-culture="@cultureCode"
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export default function RootLayout({
|
|||||||
src="/_static/dist/js/cookie-bot.js?1705409331007"
|
src="/_static/dist/js/cookie-bot.js?1705409331007"
|
||||||
/>
|
/>
|
||||||
<Script
|
<Script
|
||||||
|
strategy="beforeInteractive"
|
||||||
data-blockingmode="auto"
|
data-blockingmode="auto"
|
||||||
data-cbid="6d539de8-3e67-4f0f-a0df-8cef9070f712"
|
data-cbid="6d539de8-3e67-4f0f-a0df-8cef9070f712"
|
||||||
data-culture="@cultureCode"
|
data-culture="@cultureCode"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
TrackingProps,
|
TrackingProps,
|
||||||
} from "@/types/components/tracking"
|
} from "@/types/components/tracking"
|
||||||
import { usePathname, useSearchParams } from "next/navigation"
|
import { usePathname, useSearchParams } from "next/navigation"
|
||||||
import { useEffect } from "react"
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
function createPageObject(trackingData: TrackingData) {
|
function createPageObject(trackingData: TrackingData) {
|
||||||
const [lang, ...segments] = trackingData.pathName
|
const [lang, ...segments] = trackingData.pathName
|
||||||
@@ -65,6 +65,27 @@ export default function Tracking({ pageData }: TrackingProps) {
|
|||||||
const pathName = usePathname()
|
const pathName = usePathname()
|
||||||
const queryString = useSearchParams().toString()
|
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(() => {
|
useEffect(() => {
|
||||||
if (window.datalayer) {
|
if (window.datalayer) {
|
||||||
const trackingData = { ...pageData, pathName, queryString }
|
const trackingData = { ...pageData, pathName, queryString }
|
||||||
@@ -76,29 +97,16 @@ export default function Tracking({ pageData }: TrackingProps) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// handle consent
|
// handle consent
|
||||||
window.addEventListener(
|
window.addEventListener("CookiebotOnAccept", CookiebotCallbackOnAccept)
|
||||||
"CookiebotOnAccept",
|
window.addEventListener("CookiebotOnDecline", CookebotCallbackOnDecline)
|
||||||
function CookiebotCallback_OnAccept(e) {
|
|
||||||
if (window.Cookiebot?.changed && window.adobe) {
|
return () => {
|
||||||
if (
|
window.removeEventListener("CookiebotOnAccept", CookiebotCallbackOnAccept)
|
||||||
window._satellite.cookie
|
window.removeEventListener(
|
||||||
.get("CookieConsent")
|
"CookiebotOnDecline",
|
||||||
.includes("statistics:true")
|
CookebotCallbackOnDecline
|
||||||
) {
|
)
|
||||||
window.adobe.optIn.approve(
|
}
|
||||||
window.adobe.OptInCategories.ANALYTICS,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
window.adobe.optIn.deny(
|
|
||||||
window.adobe.OptInCategories.ANALYTICS,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
window.adobe.optIn.complete()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return null
|
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",
|
e.text = "Muuta hyväksyntäsi",
|
||||||
t.text = "Peru 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