diff --git a/app/layout.tsx b/app/layout.tsx index e29b219..2791822 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -3,6 +3,9 @@ import { Providers } from "./providers"; import "../styles/globals.css"; import { Header } from "@components/Header"; import Footer from "@components/Footer"; +import GoogleAnalytics from "@components/GoogleAnalytics"; +import CookieBanner from "@components/CookieBanner"; +import { Suspense } from "react"; export default function RootLayout({ children, @@ -11,11 +14,17 @@ export default function RootLayout({ }) { return ( + + +
-
{children}
+
+ {children} + +
diff --git a/components/CookieBanner.tsx b/components/CookieBanner.tsx new file mode 100644 index 0000000..1bba72e --- /dev/null +++ b/components/CookieBanner.tsx @@ -0,0 +1,62 @@ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ +/* eslint-disable @typescript-eslint/no-unsafe-argument */ +"use client"; + +import Link from "next/link"; +import { getLocalStorage, setLocalStorage } from "./lib/cookieStorage"; +import { useState, useEffect } from "react"; + +export default function CookieBanner() { + const [cookieConsent, setCookieConsent] = useState(undefined); + + useEffect(() => { + const storedCookieConsent = getLocalStorage("cookie_consent", null); + + setCookieConsent(storedCookieConsent); + }, [setCookieConsent]); + + useEffect(() => { + if (typeof window.gtag === "function") { + const newValue = cookieConsent ? "granted" : "denied"; + window.gtag("consent", "update", { + analytics_storage: newValue, + }); + } + + if (cookieConsent === undefined) return; + setLocalStorage("cookie_consent", cookieConsent); + }, [cookieConsent]); + return ( +
+
+ +

Cookie Policy

+

+ Tum.ai uses cookies to enhance your experience, including essential functions like logging in, saving preferences, and personalizing content. We also use Google Analytics to monitor site usage and improve our services. If you continue to use this site, you agree that we can place these types of cookies on your device. You can manage your cookie preferences at any time in your browser settings. +

+ +
+ +
+ + +
+
+ ); +} \ No newline at end of file diff --git a/components/GoogleAnalytics.tsx b/components/GoogleAnalytics.tsx new file mode 100644 index 0000000..961360f --- /dev/null +++ b/components/GoogleAnalytics.tsx @@ -0,0 +1,47 @@ +"use client"; +import Script from "next/script"; +import { usePathname, useSearchParams } from "next/navigation"; +import { useEffect } from "react"; +import { pageview } from "./lib/gtagHelper"; + +export default function GoogleAnalytics({ + GA_MEASUREMENT_ID, +}: { + GA_MEASUREMENT_ID: string; +}) { + const pathname = usePathname(); + const searchParams = useSearchParams(); + + useEffect(() => { + const url = pathname + searchParams.toString(); + + pageview(GA_MEASUREMENT_ID, url); + }, [pathname, searchParams, GA_MEASUREMENT_ID]); + return ( + <> +