Skip to content

Commit

Permalink
feat: disable consent for experimentation
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ST0R committed Oct 10, 2024
1 parent a956ad9 commit 0e30db1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
47 changes: 35 additions & 12 deletions ui/app/components/ConsentManagement.tsx
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 },
};
},
};
2 changes: 1 addition & 1 deletion ui/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function MainLayout({ children }: { children: JSX.Element }) {
<div>
<ConstructionHeader />
{children}
<ConsentBannerAndConsentManagement />
{/* <ConsentBannerAndConsentManagement /> */}
<Footer
brandTop={
<>
Expand Down

0 comments on commit 0e30db1

Please sign in to comment.