Live analytics for your Next.js app
Live analytics for Next.js: one component, one middleware, and you see page views, crawler visits, 404s, errors and your own events as they happen.
Three steps to install
npm install @mettr/next
// app/layout.tsx import { Mettr } from '@mettr/next'; <head> <Mettr /> </head>
// proxy.ts (Next 16), or middleware.ts (Next 15) import { withMettr } from '@mettr/next/middleware'; export const proxy = withMettr();
Set METTR_SECRET_KEY and METTR_PUBLIC_KEY, and it sends from production only. Next.js 15.1 or later, App Router.
What you get without writing code
- Page views, navigation and who is online, from the browser script, loaded and sent through
/_liveon your own domain, so ad blockers mostly let it through. - Crawler visits: Googlebot, Bingbot, GPTBot, ClaudeBot and the rest seldom run scripts. The middleware sees them, and mettr names each and keeps them apart from your visitors.
- 404s and errors:
reportNotFound()in your not-found page andonRequestErrorininstrumentation.ts. Errors go by their class, never their message.
Your own events, server or client
import { track } from '@mettr/next/server'; await track('signup', { plan: 'pro' }, { userId: user.id });
From a server action or a route handler, sent after the response. In a client component, track from @mettr/next/client does the same in the browser.
Revenue from your own billing
Stripe, Paddle and Polar are read by mettr itself. Billing of your own? getMettr() gives the Node client, and subscription() sends each subscription as it changes: MRR, churn and revenue by source follow.
Open source
@mettr/next is MIT licensed, on GitHub and npm. The full guide.
Read on
Next.js
The @mettr/next package adds the browser script, serves it from your own domain, and sends crawler visits, 404s, errors and your events from the App Router.
Product events
Send your product's own events from the server, with the user and their properties: sign-ups, upgrades, exports. Live on the dashboard, in funnels and breakdowns, beyond the reach of ad blockers.
Node.js analytics
Live analytics for Node.js, Bun, Deno and Workers: middleware for Express, Fastify and Hono sends crawler visits, 404s, errors, response times and your events.
See your site live in two minutes
Free for one site. No card, no cookie banner