Skip to content

Commit

Permalink
feat: ajout du consentement
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ST0R committed Sep 18, 2024
1 parent cb0e0a0 commit 26b2d41
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
21 changes: 21 additions & 0 deletions ui/app/components/ConsentManagement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use client";

import { createConsentManagement } from "@codegouvfr/react-dsfr/consentManagement";

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.",
},
}),
});
8 changes: 6 additions & 2 deletions ui/app/components/LogRocketInitializer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"use client";
import { useEffect } from "react";
import LogRocket from "logrocket";
import { useConsent } from "./ConsentManagement";

export function LogRocketInitializer() {
const { finalityConsent } = useConsent();

useEffect(() => {
process.env.NEXT_PUBLIC_LOGROCKET &&
finalityConsent?.analytics &&
process.env.NEXT_PUBLIC_LOGROCKET &&
LogRocket.init(process.env.NEXT_PUBLIC_LOGROCKET, {
network: {
requestSanitizer: (request) => {
Expand Down Expand Up @@ -34,6 +38,6 @@ export function LogRocketInitializer() {
},
},
});
});
}, [finalityConsent]);
return null;
}
17 changes: 17 additions & 0 deletions ui/app/components/Plausible.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use client";
import PlausibleProvider from "next-plausible";
import { useConsent } from "./ConsentManagement";

export function Plausible() {
const { finalityConsent } = useConsent();

return (
finalityConsent?.analytics && (
<PlausibleProvider
domain={process.env.NEXT_PUBLIC_DOMAIN || ""}
trackOutboundLinks={true}
taggedEvents={true}
></PlausibleProvider>
)
);
}
9 changes: 2 additions & 7 deletions ui/app/components/RootLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { getHtmlAttributes } from "@codegouvfr/react-dsfr/next-appdir/getHtmlAtt
import StartDsfr from "#/app/StartDsfr";
import { defaultColorScheme } from "#/app/defaultColorScheme";
import Link from "next/link";
import PlausibleProvider from "next-plausible";
import { LogRocketInitializer } from "./LogRocketInitializer";
import { Plausible } from "./Plausible";

export default function RootLayout({ title, children }: { title?: string; children: JSX.Element }) {
const lang = "fr";

return (
<html
{...getHtmlAttributes({ defaultColorScheme, lang })}
Expand Down Expand Up @@ -39,11 +38,7 @@ export default function RootLayout({ title, children }: { title?: string; childr
// //"Spectral-ExtraBold"
]}
/>
<PlausibleProvider
domain={process.env.NEXT_PUBLIC_DOMAIN || ""}
trackOutboundLinks={true}
taggedEvents={true}
></PlausibleProvider>
<Plausible />
<LogRocketInitializer />
</head>
<body
Expand Down
2 changes: 2 additions & 0 deletions ui/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./(accompagnateur)/style.scss";
import Title from "./(accompagnateur)/components/Title";
import Footer from "./components/Footer";
import Link from "./components/Link";
import { ConsentBannerAndConsentManagement } from "./components/ConsentManagement";

export default function MainLayout({ children }: { children: JSX.Element }) {
return (
Expand All @@ -15,6 +16,7 @@ export default function MainLayout({ children }: { children: JSX.Element }) {
<Layout header={<Header title={title} tagline={tagline} />} title={title}>
<>
{children}
<ConsentBannerAndConsentManagement />
<Footer
brandTop={
<>
Expand Down

0 comments on commit 26b2d41

Please sign in to comment.