-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: disable consent for experimentation
- Loading branch information
Showing
2 changed files
with
36 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,44 @@ | ||
"use client"; | ||
|
||
import { useLocalStorage } from "usehooks-ts"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { createConsentManagement } from "@codegouvfr/react-dsfr/consentManagement"; | ||
import { useEffect } from "react"; | ||
|
||
export const { | ||
ConsentBannerAndConsentManagement, | ||
FooterConsentManagementItem, | ||
FooterPersonalDataPolicyItem, | ||
useConsent, | ||
} = createConsentManagement({ | ||
finalityDescription: ({ lang }) => ({ | ||
analytics: { | ||
title: "Analyse", | ||
description: "Nous utilisons des cookies pour mesurer l’audience de notre site et améliorer son contenu.", | ||
}, | ||
// personalization: { | ||
// title: "Personnalisation", | ||
// description: "Nous utilisons des cookies pour vous proposer des contenus adaptés à vos centres d’intérêts.", | ||
// }, | ||
} = { | ||
...createConsentManagement({ | ||
finalityDescription: ({ lang }) => ({ | ||
analytics: { | ||
title: "Analyse", | ||
description: "Nous utilisons des cookies pour mesurer l’audience de notre site et améliorer son contenu.", | ||
}, | ||
// personalization: { | ||
// title: "Personnalisation", | ||
// description: "Nous utilisons des cookies pour vous proposer des contenus adaptés à vos centres d’intérêts.", | ||
// }, | ||
}), | ||
}), | ||
}); | ||
useConsent: () => { | ||
// Override useConsent for now (experimentation) | ||
const searchParams = useSearchParams(); | ||
const disableTrackingParams = searchParams.get("notracking") ? searchParams.get("notracking") === "true" : null; | ||
const [disableTracking, saveDisableTracking] = useLocalStorage<boolean>( | ||
"disableTracking", | ||
disableTrackingParams !== null ? disableTrackingParams : false | ||
); | ||
|
||
useEffect(() => { | ||
if (disableTrackingParams !== null) { | ||
saveDisableTracking(disableTrackingParams); | ||
} | ||
}, [disableTrackingParams]); | ||
|
||
return { | ||
finalityConsent: { analytics: !disableTracking }, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters