Next.js Native Open-Source Analytics
100% server-side. No client JavaScript. No cookies. No GDPR banners.
Just accurate analytics that respect your users.
Website · Integrations · Demo
Nextlytics is a server-side analytics library for Next.js. It tracks page views automatically via middleware and lets you send custom events from server components, server actions, and API routes.
There's no client-side JavaScript involved. Events go directly from your server to your analytics backend. This means no ad blockers, no cookies, and accurate data.
It works with multiple backends — Segment, PostHog, Google Analytics, or you can write directly to a database like ClickHouse or Postgres.
npm install @nextlytics/core1. Configure your backend (src/nextlytics.ts)
import { Nextlytics } from "@nextlytics/core";
import { segmentBackend } from "@nextlytics/core/backends/segment";
export const { middleware, handlers, analytics } = Nextlytics({
backends: [
segmentBackend({
writeKey: process.env.SEGMENT_WRITE_KEY!,
}),
],
});2. Add to layout (src/app/layout.tsx)
import { NextlyticsServer } from "@nextlytics/core/server";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<NextlyticsServer>{children}</NextlyticsServer>
</body>
</html>
);
}3. Export middleware (src/middleware.ts)
import { middleware } from "./nextlytics";
export { middleware };That's it. Every page view is now tracked server-side.
| Backend | Type |
|---|---|
| Segment / Jitsu | CDP |
| PostHog | Product Analytics |
| Google Analytics | Web Analytics |
| ClickHouse | Database |
| Neon / Supabase | Database |
MIT