diff --git a/front/src/app/layout.tsx b/front/src/app/layout.tsx index 9c0acbb..4732fe5 100644 --- a/front/src/app/layout.tsx +++ b/front/src/app/layout.tsx @@ -1,7 +1,11 @@ import React from "react"; import "./globals.css"; import { FooterComponent, HeaderComponent } from "../layouts"; -import { CookiesConsentProvider, CookiesBanner } from "../common/cookies"; +import { + CookiesConsentProvider, + CookiesBanner, + GoogleAnalytics, +} from "../common/cookies"; interface Props { children: React.ReactNode; @@ -20,6 +24,7 @@ const RootLayout = (props: Props) => {
{children}
+ diff --git a/front/src/common/cookies/google-analytics.component.tsx b/front/src/common/cookies/google-analytics.component.tsx new file mode 100644 index 0000000..e78e113 --- /dev/null +++ b/front/src/common/cookies/google-analytics.component.tsx @@ -0,0 +1,31 @@ +"use client"; + +import Script from "next/script"; +import { useCookiesConsent } from "./cookies-consent.context"; + +const GA_ID = "G-0SF5QPC7FQ"; + +export const GoogleAnalytics: React.FC = () => { + const { consent } = useCookiesConsent(); + + if (consent !== "accepted") { + return null; + } + + return ( + <> + + + ); +}; diff --git a/front/src/common/cookies/index.ts b/front/src/common/cookies/index.ts index 085c71f..d058290 100644 --- a/front/src/common/cookies/index.ts +++ b/front/src/common/cookies/index.ts @@ -1,3 +1,4 @@ export { CookiesConsentProvider, useCookiesConsent } from "./cookies-consent.context"; export { CookiesBanner } from "./cookies-banner.component"; export { CookiesResetButton } from "./cookies-reset-button.component"; +export { GoogleAnalytics } from "./google-analytics.component";