1
0
Fork 0
mirror of https://github.com/betagouv/mon-entreprise synced 2025-03-12 18:36:04 +00:00

chore: corrige le consentement de PA

This commit is contained in:
Alice Dahan 2025-03-04 19:05:29 +01:00 committed by liliced
parent 31b9f8440a
commit 933565c87f
2 changed files with 33 additions and 5 deletions

View file

@ -2,6 +2,15 @@
declare global {
interface Window {
pa: ATTracker
pdl: {
requireConsent: string
consent: {
defaultPreset: {
PA: string
}
products?: string[]
}
}
}
}

View file

@ -14,11 +14,9 @@ export function TrackingProvider({ children }: { children: React.ReactNode }) {
const [injected, setInjected] = useState<boolean>(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 }) {
</TrackingContext.Provider>
)
}
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
}