Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GlobalErrorHandler } from "@/components/GlobalErrorHandler";
import AIProvider from "@/components/ai/AIProvider";
import { getPageStructuredData } from "@/lib/seo/metadata";
import { usePathname } from "next/navigation";
import { Analytics } from '@vercel/analytics/react';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Gate Vercel Analytics behind stored consent before rendering.

Line 92 mounts <Analytics /> for every user, but your consent model (lib/analytics-cookies.ts:44-50, lib/analytics-cookies.ts:53-60) defaults analytics to off and exposes a consent check. This can trigger tracking before consent.

🔧 Suggested fix
+import { useEffect, useState } from "react";
 import { Analytics } from '@vercel/analytics/react';
+import { analyticsCookies } from "@/lib/analytics-cookies";

 export default function RootLayout({
   children,
 }: Readonly<{
   children: React.ReactNode;
 }>) {
+  const [canTrackAnalytics, setCanTrackAnalytics] = useState(false);
+
+  useEffect(() => {
+    setCanTrackAnalytics(analyticsCookies.hasConsent());
+  }, []);
+
   const structuredData = getPageStructuredData('home');
   const pathname = usePathname();

@@
-            <Analytics />
+            {canTrackAnalytics && <Analytics />}
           </ThemeProvider>

Also applies to: 92-92

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/layout.tsx` at line 9, The <Analytics /> component in app/layout.tsx must
be rendered only when the user has given consent: import and call the consent
helper (e.g. getAnalyticsConsent or hasAnalyticsConsent from
lib/analytics-cookies.ts) and conditionally render <Analytics /> only if it
returns true; ensure this check runs client-side (wrap the analytics rendering
in a client component or use a useEffect/hydration check) so analytics is never
mounted before stored consent is confirmed.


// Only load dev tools in development
const ReactDevTools = () => null;
Expand Down Expand Up @@ -88,6 +89,7 @@ export default function RootLayout({

<ReactDevTools />
<AuthDebug />
<Analytics />
</ThemeProvider>
</ErrorBoundary>
</body>
Expand Down
Loading
Loading