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 🙏

© 2025 – Pkg Stats / Ryan Hefner

next-rybbit

v0.1.18

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 | | autoTrackPageview | string | ❌ | true | Set to "false" to disable automatic tracking of the initial pageview when the script loads. You will need to manually call window.rybbit.pageview() to track pageviews. | | trackSpa | string | ❌ | true | Set to "false" to disable automatic pageview tracking for single page applications (React, Vue, etc). You will need to manually call window.rybbit.pageview() or window.rybbit.track() for all but the initial pageview. | | trackQuery | string | ❌ | true | Set to "false" to disable tracking of URL query strings. This enhances privacy by preventing potentially sensitive information in query parameters from being stored in your analytics data. | | trackOutbound | string | ❌ | true | Set to "false" to disable automatic tracking of outbound link clicks. | | trackErrors | string | ❌ | false | Set to "true" to enable automatic tracking of JavaScript errors and unhandled promise rejections. Only tracks errors from the same origin to avoid noise from third-party scripts. | | sessionReplay | string | ❌ | false | Set to "true" to enable session replay recording. Captures user interactions, mouse movements, and DOM changes for debugging and user experience analysis. | | webVitals | string | ❌ | false | Set to "true" to enable Web Vitals performance metrics collection (LCP, CLS, INP, FCP, TTFB). Web Vitals are disabled by default to reduce script size and network requests. | | skipPatterns | string[] | ❌ | [] | A JSON string array of URL path patterns to ignore. Pageviews matching these patterns won’t be tracked. Supports two types of wildcards: * (matches within a segment) and ** (matches across segments). | | maskPatterns | string[] | ❌ | [] | A JSON string array of URL path patterns to mask for privacy. Pageviews matching these patterns will be tracked, but the actual URL path will be replaced with the pattern itself in analytics data. Supports the same wildcards as data-skip-patterns. | | debounce | string | ❌ | 500 | The delay (in milliseconds) before tracking a pageview after URL changes via the History API (pushState, replaceState). Set to 0 to disable debouncing. | | apiKey | string | ❌ | - | API key for tracking from localhost during development. Bypasses origin validation. | | 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, 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
});

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