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

@rironib/analytics

v1.0.0

Published

A unified analytics provider for Next.js - Integrate Google Analytics, Plausible, Fathom, Mixpanel, Segment, Hotjar, Clarity, and more with a single component

Downloads

8

Readme

Analytics Provider for Next.js App Router

A unified, easy-to-use analytics provider specifically designed for Next.js App Router applications. Integrate multiple analytics platforms with a single component.

Features

8 Analytics Providers - Support for Google Analytics, Ahrefs, Plausible, Fathom, Mixpanel, Segment, Hotjar, and Microsoft Clarity

🚀 Zero Configuration - Just pass your tracking IDs and you're done

Performance Optimized - Uses Next.js Script component with afterInteractive strategy

🎯 TypeScript Support - Fully typed for better developer experience

🔒 Privacy-Focused Options - Includes privacy-first analytics like Plausible and Fathom

📦 Tree-Shakeable - Only bundle the providers you use

🎨 Next.js App Router Ready - Designed specifically for the App Router architecture

Installation

npm install @rironib/analytics
# or
yarn add @rironib/analytics
# or
pnpm add @rironib/analytics

Usage

Basic Usage (Next.js App Router)

Add the AnalyticsProvider component to your app/layout.tsx:

import { AnalyticsProvider } from "@rironib/analytics";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <head>
        <AnalyticsProvider
          google={process.env.NEXT_PUBLIC_GA_ID}
          plausible="yourdomain.com"
          clarity={process.env.NEXT_PUBLIC_CLARITY_ID}
        />
      </head>
      <body>{children}</body>
    </html>
  );
}

Supported Providers

Google Analytics

<AnalyticsProvider google="G-XXXXXXXXXX" />

Ahrefs

<AnalyticsProvider ahrefs="GTM-XXXXXXX" />

Plausible

<AnalyticsProvider plausible="yourdomain.com" />

Fathom

<AnalyticsProvider fathom="ABCDEFGH" />

Mixpanel

<AnalyticsProvider mixpanel="your-token" />

Segment

<AnalyticsProvider segment="your-write-key" />

Hotjar

<AnalyticsProvider hotjar="1234567" />

Microsoft Clarity

<AnalyticsProvider clarity="abcdefghij" />

Multiple Providers

You can use multiple analytics providers simultaneously:

<AnalyticsProvider
  google={process.env.NEXT_PUBLIC_GA_ID}
  plausible="yourdomain.com"
  clarity={process.env.NEXT_PUBLIC_CLARITY_ID}
  hotjar={process.env.NEXT_PUBLIC_HOTJAR_ID}
/>

Environment Variables

Create a .env.local file in your Next.js project:

NEXT_PUBLIC_GA_ID=G-XXXXXXXXXX
NEXT_PUBLIC_AHREFS_ID=GTM-XXXXXXX
NEXT_PUBLIC_PLAUSIBLE_DOMAIN=yourdomain.com
NEXT_PUBLIC_FATHOM_ID=ABCDEFGH
NEXT_PUBLIC_MIXPANEL_TOKEN=your-token
NEXT_PUBLIC_SEGMENT_KEY=your-write-key
NEXT_PUBLIC_HOTJAR_ID=1234567
NEXT_PUBLIC_CLARITY_ID=abcdefghij

Then use them in your component:

<AnalyticsProvider
  google={process.env.NEXT_PUBLIC_GA_ID}
  ahrefs={process.env.NEXT_PUBLIC_AHREFS_ID}
  plausible={process.env.NEXT_PUBLIC_PLAUSIBLE_DOMAIN}
  fathom={process.env.NEXT_PUBLIC_FATHOM_ID}
  mixpanel={process.env.NEXT_PUBLIC_MIXPANEL_TOKEN}
  segment={process.env.NEXT_PUBLIC_SEGMENT_KEY}
  hotjar={process.env.NEXT_PUBLIC_HOTJAR_ID}
  clarity={process.env.NEXT_PUBLIC_CLARITY_ID}
/>

Individual Provider Components

You can also import and use individual provider components:

import { GoogleAnalytics, PlausibleAnalytics } from "@rironib/analytics";

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <head>
        <GoogleAnalytics id={process.env.NEXT_PUBLIC_GA_ID} />
        <PlausibleAnalytics id="yourdomain.com" />
      </head>
      <body>{children}</body>
    </html>
  );
}

API Reference

AnalyticsProvider Props

| Prop | Type | Description | | ----------- | -------- | ---------------------------------------------- | | google | string | Google Analytics measurement ID (G-XXXXXXXXXX) | | ahrefs | string | Ahrefs/GTM container ID (GTM-XXXXXXX) | | plausible | string | Your domain name for Plausible | | fathom | string | Fathom site ID | | mixpanel | string | Mixpanel project token | | segment | string | Segment write key | | hotjar | string | Hotjar site ID | | clarity | string | Microsoft Clarity project ID |

TypeScript

This package includes TypeScript definitions. All props are fully typed for a better development experience.

import type { AnalyticsProviderProps } from "@rironib/analytics";

const analyticsConfig: AnalyticsProviderProps = {
  google: "G-XXXXXXXXXX",
  plausible: "yourdomain.com",
};

Performance

All analytics scripts are loaded using Next.js's Script component with the afterInteractive strategy, ensuring they don't block the initial page load. This provides optimal performance while still capturing all necessary analytics data.

Privacy

This package includes several privacy-focused analytics providers:

  • Plausible - No cookies, GDPR compliant
  • Fathom - Privacy-first, GDPR compliant

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © rironib

Support

If you encounter any issues or have questions, please file an issue on the GitHub repository.