diff --git a/src/components/conditional-analytics.tsx b/src/components/conditional-analytics.tsx index 66d1cb9..229e800 100644 --- a/src/components/conditional-analytics.tsx +++ b/src/components/conditional-analytics.tsx @@ -1,24 +1,39 @@ "use client"; -import { useEffect, useState } from "react"; import { Analytics } from "@vercel/analytics/next"; import { SpeedInsights } from "@vercel/speed-insights/next"; export function ConditionalAnalytics() { - const [analyticsEnabled, setAnalyticsEnabled] = useState(false); - - useEffect(() => { - // check if analytics are enabled - const enabled = localStorage.getItem("analytics-enabled") === "true"; - setAnalyticsEnabled(enabled); - }, []); - - if (!analyticsEnabled) return null; - return ( <> - - + { + // check if user has consented + const analyticsEnabled = localStorage.getItem("analytics-enabled") === "true"; + + // if not consented, return null to block the event + if (!analyticsEnabled) { + return null; + } + + // if consented, return the event to send it + return event; + }} + /> + { + // check if user has consented + const analyticsEnabled = localStorage.getItem("analytics-enabled") === "true"; + + // if not consented, return null to block the event + if (!analyticsEnabled) { + return null; + } + + // if consented, return the event to send it + return event; + }} + /> ); } \ No newline at end of file diff --git a/src/components/cookie-notice.tsx b/src/components/cookie-notice.tsx index be87771..027bca5 100644 --- a/src/components/cookie-notice.tsx +++ b/src/components/cookie-notice.tsx @@ -23,7 +23,6 @@ export function CookieConsent() { onClick: () => { localStorage.setItem("cookie-consent", "accepted"); localStorage.setItem("analytics-enabled", "true"); - window.location.reload(); }, }, cancel: {