npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@clipper-dev/mongolytics-next

v1.0.7

Published

Self-hosted, MongoDB-powered analytics for React/Next.js

Readme

mongolytics-next

NPM Version License

A lightweight, self-hosted analytics solution for Next.js applications, supporting both the App Router and Pages Router. Powered by your own MongoDB database, Mongolytics allows you to take full ownership of your user data.

Key Features

  • ✅ Universal Next.js Support: Simple, consistent setup for both App and Pages Routers.
  • ✅ Full Data Ownership: Your analytics data is stored in your own MongoDB instance.
  • 🚀 Drop-in Component: Get started in minutes with a simple API handler and a single React component.
  • ⚡️ Performant & Non-Blocking: Designed to be invisible. The tracking script uses navigator.sendBeacon to ensure it never slows down your user experience.

Prerequisites

  • A Next.js project (v12+).
  • Access to a MongoDB database and its connection string. A free cluster on MongoDB Atlas is a perfect way to start.

Installation

npm install @clipper-dev/mongolytics-next uuid
npm install -D @types/uuid

Setup Guide

Getting started is a simple three-step process.

Step 1: Configure Environment Variables

Create a .env.local file in the root of your Next.js project. This tells Mongolytics how to connect to your database.

# .env.local

MONGOLYTICS_URI="your-mongodb-atlas-connection-string"
MONGOLYTICS_DB_NAME="your-analytics-database-name"

Step 2: Create the API Endpoint

This single API endpoint securely receives tracking data. Choose the setup for your router type.

For App Router (Next.js 13+)

Create a new file at app/api/mongolytics/route.ts and export our pre-built handler.

// app/api/mongolytics/route.ts
import { mongolyticsAppRouteHandler as POST } from '@clipper-dev/mongolytics-next/server';

export { POST };

For Pages Router (Legacy)

Create a new file at pages/api/mongolytics.ts.

// pages/api/mongolytics.ts
import { mongolyticsPagesRouterHandler } from '@clipper-dev/mongolytics-next/server';

export default mongolyticsPagesRouterHandler;

Step 3: Add the Tracking Component

Add the <Mongolyth /> component to your root layout file. It automatically detects page changes and sends tracking events.

For App Router (Next.js 13+)

Add the component to app/layout.tsx.

// app/layout.tsx
import { Mongolyth } from '@clipper-dev/mongolytics-next/client';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <Mongolyth />
        {children}
      </body>
    </html>
  );
}

For Pages Router (Legacy)

Add the component to pages/_app.tsx and specify the routerType.

// pages/_app.tsx
import { Mongolyth } from '@clipper-dev/mongolytics-next/client';
import type { AppProps } from 'next/app';

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <>
      <Mongolyth routerType="pages" />
      <Component {...pageProps} />
    </>
  );
}

export default MyApp;

Advanced Usage: The useMongolytics Hook

For more complex use cases where you might need to integrate analytics tracking with other logic, you can use the underlying useMongolytics hook directly instead of the <Mongolyth /> component.

'use client';

import { useMongolytics } from '@clipper-dev/mongolytics-next/client';

function MyCustomComponent() {
  // For App Router (default)
  useMongolytics();

  // For Pages Router
  useMongolytics({ routerType: 'pages' });

  // ... your other component logic
  return <div>...</div>
}

Verification

Deploy your application. You can verify it's working by visiting a few pages and checking your MongoDB database for a new sessions collection containing user session documents.