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

next-rybbit

v0.2.2

Published

Simple integration for Rybbit Analytics in Next.js applications

Readme

next-rybbit

Next.js integration for Rybbit Analytics - A simple, privacy-focused analytics solution.

Installation

npm install next-rybbit
# or
yarn add next-rybbit
# or
pnpm add next-rybbit

Usage

App Router (Recommended)

Wrap your app in the RybbitProvider in your root layout:

// app/layout.tsx
import { RybbitProvider } from 'next-rybbit';

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

Pages Router

Wrap your app in the RybbitProvider in _app.tsx:

// pages/_app.tsx
import { RybbitProvider } from 'next-rybbit';
import type { AppProps } from 'next/app';

export default function App({ Component, pageProps }: AppProps) {
  return (
    <RybbitProvider siteId="YOUR_SITE_ID">
      <Component {...pageProps} />
    </RybbitProvider>
  );
}

Configuration

Props

| Prop | Type | Required | Default | Description | |----------------------|------|----------|---------|-------------| | siteId | string | ✅ | - | Your Rybbit site ID | | analyticsHost | string | ❌ | https://app.rybbit.io/api | Custom analytics host URL | | children | React.ReactNode | ✅ | - | Your app content |

Custom Analytics Host

If you're using a self-hosted Rybbit instance, you can specify a custom analytics host:

<RybbitProvider 
  siteId="YOUR_SITE_ID" 
  analyticsHost="https://your-custom-host.com/api"
>
  {children}
</RybbitProvider>

How it works

The RybbitProvider component automatically loads the Rybbit analytics script with the correct configuration. It uses Next.js's Script component with the afterInteractive strategy to ensure optimal performance.

The script is loaded from {analyticsHost}/script.js and configured with your site ID.

Tracking API

You can use the useRybbit hook to access tracking functions in your components:

import { useRybbit } from 'next-rybbit';

function MyComponent() {
  const { trackEvent, trackPageview, identify, setTraits, clearUserId, getUserId } = useRybbit();
  
  // Use tracking functions here
}

trackEvent

Tracks a custom event with a name and optional parameters.

const { trackEvent } = useRybbit();

// Basic usage - just the event name
trackEvent('button_clicked');

// With custom properties
trackEvent('product_purchased', {
  props: {
    productId: 'prod-123',
    price: 49.99,
    currency: 'USD'
  }
});

// With callback function
trackEvent('form_submitted', {
  props: { formId: 'contact' },
  callback: () => {
    console.log('Event tracked successfully');
  }
});

trackPageview

Tracks a page view with optional parameters.

const { trackPageview } = useRybbit();

// Basic usage - tracks current page
trackPageview();

// With custom URL and properties
trackPageview({
  url: '/custom-path',
  referrer: 'https://example.com',
  deviceWidth: 1024,
  props: {
    section: 'blog',
    category: 'tech'
  }
});

identify

Associates the current visitor with a user ID and optional properties.

const { identify } = useRybbit();

// Basic usage - just set user ID
identify('user-123');

// With user properties
identify('user-123', {
  plan: 'premium',
  subscribed: true,
  loginCount: 42
});

setTraits

Updates traits for the currently identified user without re-identifying them. Requires identify() to have been called first.

const { setTraits } = useRybbit();

// Update user traits
setTraits({
  plan: 'enterprise',
  upgraded_at: '2024-01-15'
});

// Remove a trait by setting it to null
setTraits({
  temporary_flag: null
});

clearUserId

Clears the currently set user ID.

const { clearUserId } = useRybbit();

// Use on logout
const handleLogout = () => {
  // Logout logic
  clearUserId();
};

getUserId

Returns the currently set user ID.

const { getUserId } = useRybbit();

// Check if user is identified
const currentUserId = getUserId();
if (currentUserId) {
  console.log('User is identified as:', currentUserId);
} else {
  console.log('User is anonymous');
}

TypeScript Support

This package includes full TypeScript support with type definitions.

License

MIT