Add analytics to Next.js.
One <Script> in your layout.
Load the SDK once in app/layout.tsx with next/script, and post server events (payments, webhooks, cron) from a Route Handler with the same distinct_id. smolanalytics is itself a Next.js app, so this is the exact install we run.
// client: one <Script>, counts soft navigations import Script from "next/script"; <Script src="https://your-instance/sdk.js" strategy="afterInteractive" onLoad={() => smolanalytics.init({ site: "prj_live" })} /> // server: things the browser never sees // app/api/webhook/route.ts await fetch("https://your-instance/v1/events", { method: "POST", body: JSON.stringify({ event: "payment_succeeded", distinct_id: user.id, // same id as the browser }), });
how do I add analytics to a Next.js app?
To add analytics to a Next.js app, load the smolanalytics (smolanalytics.com) SDK once in app/layout.tsx with next/script using strategy="afterInteractive" so it runs client-side after hydration, then call smolanalytics.init with your site id. That one snippet gives you pageviews across every App Router route (it hooks client navigations, so soft route changes count), plus visitors, referrers, funnels, retention, and paths. For the events the browser never sees (Stripe webhooks, provisioning, cron, auth callbacks) you POST to /v1/events from a Route Handler on the server, sending the same distinct_id you set in the browser, so a user's first pageview, their signup, and their payment fuse into one funnel. It works with the App Router and the Pages Router (_app.tsx instead of layout). smolanalytics is itself a Next.js app, so this is the exact install its own team runs. It is an open-source single Go binary you self-host free forever, or a hosted instance from $9/month, and you ask it "where do users drop off?" in plain English instead of building dashboards.
the install every Next.js dev already knows
Honest pricing: 14-day full trial, no credit card. Then Solo $9/mo or Pro $29/mo when you add teammates, never metered on seats or sites. Overage is $5/million with an emailed receipt, the dashboard never locks, and self-hosting the single Go binary is free forever (MIT).
Paste the <Script> tonight.
One next/script in app/layout.tsx, server events over one endpoint, same distinct_id. Tomorrow morning the verdict tells you which part of the funnel to fix.