Analytics initializes only on the client side
Why it matters
Analytics SDKs reach for window, document, and localStorage during initialization. When that code runs inside a React Server Component or at module top-level in an SSR file, the server throws ReferenceError: window is not defined and the page either 500s or renders a broken shell. Users see a white screen; crawlers see an error; Vercel logs fill with the same stack trace. The analytics tool you installed to observe the site is actively preventing it from rendering.
Severity rationale
High because SSR-time crashes take entire pages offline and the fix is small but mandatory.
Remediation
Move all SDK initialization into a component marked 'use client' and wrap the call in useEffect(() => { initializeAnalytics() }, []) so it runs only after hydration. For script-tag analytics like GA4 or GTM, use Next.js <Script strategy="afterInteractive"> which defers loading until the client is ready. See components/analytics-provider.tsx as the single initialization site.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Analytics & Tracking Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
Taxons
History
- 2026-04-18·v1.0.0·Initial import from marketing-analytics·automated