Answers
What's the best privacy-friendly Google Analytics alternative for a Next.js app?
Privacy-friendly analytics for a Next.js app: no cookie before consent, one component in the root layout, and numbers your agent reads.
Updated
For a Next.js app, nextanalytica adds one <Analytics> component to app/layout.tsx, counts without cookies until a visitor agrees, and lets your agent read the numbers over MCP. Plausible, Fathom and Umami set no cookies at all and give people a dashboard; Vercel Web Analytics works for projects on Vercel, with custom events on some plans.
How do you do it?
- Run
pnpm add @nextanalytica/tag@1. - Add
<Analytics project="na_…" />inapp/layout.tsx. - Pass your cookie banner's answer with
consent()on every page, if you have one. - Connect your agent: in Claude Code,
claude mcp add --transport http nextanalytica https://mcp.nextanalytica.app/mcp, then/mcpto sign in.
What can you ask your agent?
- "How many visits did the app get this week, and from where?"