From 933565c87f6e1cf69d770c01802233a19fc995ac Mon Sep 17 00:00:00 2001 From: Alice Dahan Date: Tue, 4 Mar 2025 19:05:29 +0100 Subject: [PATCH] chore: corrige le consentement de PA --- .../components/ATInternetTracking/Tracker.ts | 9 ++++++ site/source/components/TrackingProvider.tsx | 29 +++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/site/source/components/ATInternetTracking/Tracker.ts b/site/source/components/ATInternetTracking/Tracker.ts index 914fbb7c9..e36ad630a 100644 --- a/site/source/components/ATInternetTracking/Tracker.ts +++ b/site/source/components/ATInternetTracking/Tracker.ts @@ -2,6 +2,15 @@ declare global { interface Window { pa: ATTracker + pdl: { + requireConsent: string + consent: { + defaultPreset: { + PA: string + } + products?: string[] + } + } } } diff --git a/site/source/components/TrackingProvider.tsx b/site/source/components/TrackingProvider.tsx index 307ed6a48..f3fc78bc0 100644 --- a/site/source/components/TrackingProvider.tsx +++ b/site/source/components/TrackingProvider.tsx @@ -14,11 +14,9 @@ export function TrackingProvider({ children }: { children: React.ReactNode }) { const [injected, setInjected] = useState(false) useEffect(() => { - const script = document.createElement('script') - script.src = 'https://tag.aticdn.net/piano-analytics.js' - script.type = 'text/javascript' - script.crossOrigin = 'anonymous' - script.async = true + configureConsent() + + const script = prepareScript() script.onload = () => { const siteId = import.meta.env.VITE_AT_INTERNET_SITE_ID @@ -83,3 +81,24 @@ export function TrackingProvider({ children }: { children: React.ReactNode }) { ) } + +const configureConsent = () => { + window.pdl = window.pdl || {} + window.pdl.requireConsent = 'v2' + window.pdl.consent = { + defaultPreset: { + PA: 'essential', + }, + } + window.pdl.consent.products = ['PA'] +} + +const prepareScript = (): HTMLScriptElement => { + const script = document.createElement('script') + script.src = 'https://tag.aticdn.net/piano-analytics.js' + script.type = 'text/javascript' + script.crossOrigin = 'anonymous' + script.async = true + + return script +}