Skip to content

NextCollect - streamline analytics platform integrations in Next.js

License

Notifications You must be signed in to change notification settings

jitsucom/nextlytics

Repository files navigation

Nextlytics

Nextlytics

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


What is Nextlytics?

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.

Install

npm install @nextlytics/core

Quick Start

1. 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.

Supported Backends

Backend Type
Segment / Jitsu CDP
PostHog Product Analytics
Google Analytics Web Analytics
ClickHouse Database
Neon / Supabase Database

See all integrations →

License

MIT