chore: upgrade Vercel Analytics to v2 + App Router route tracking

Merged
SW
5mo ago
+72-96

What

Brings chat's Vercel Web Analytics up to the current recommended setup. Three changes:

  1. Switch @vercel/analytics/react โ†’ @vercel/analytics/next. chat is a Next.js App Router app, but it imported the generic /react Analytics component, which doesn't hook into Next's router. Result: only the initial page load was tracked, client-side route changes (SPA navigations) were not registered as page views. The /next variant adds App Router route detection.
  2. Bump @vercel/analytics 1.6.1 โ†’ 2.0.1. v2 adds Resilient Intake (more robust delivery against ad-blockers / network loss), is now MIT-licensed, and replaces the deprecated endpoint option with eventEndpoint/viewEndpoint. The <Analytics /> API is unchanged for our usage.
  3. Drop the DeferredAnalytics wrapper. components/DeferredAnalytics.tsx wrapped <Analytics /> in next/dynamic with ssr:false. That's redundant โ€” <Analytics /> is already a client component that lazy-loads its script. The root layout now renders <Analytics /> from /next directly, per the Vercel quickstart.

Why

The route-tracking fix (#1) is the substantive one: it means analytics now reflect real navigation within the app, not just first loads. #2 and #3 are housekeeping to match the current docs and remove dead indirection.

Verification

  • tsc --noEmit: no new type errors introduced (the 7 pre-existing errors in lib/emails/__tests__/extractSendEmailResults.test.ts are present on main and unrelated).
  • pnpm build: client/layout compiles successfully. The local build can't fully complete because API routes require env vars at module load (ARWEAVE_KEY, Supabase creds) that aren't set locally โ€” unrelated to this change. The Vercel preview build (full env) is the green gate.

๐Ÿค– Generated with Claude Code


Summary by cubic

Upgrade Vercel Web Analytics to v2 and switch to @vercel/analytics/next so App Router navigations are tracked as page views, not just the initial load. Remove the custom deferred wrapper and render <Analytics /> directly in the root layout.

  • Refactors

    • Delete components/DeferredAnalytics.tsx; <Analytics /> already lazy-loads client-side.
  • Dependencies

    • Bump @vercel/analytics to ^2.0.1 (adds Resilient Intake, MIT license).