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

hydrate-beer

v2.0.2

Published

Zero-config performance monitoring for React and Next.js with PostHog

Readme

🍺 hydrate-beer

Zero-config performance monitoring SDK for React and Next.js applications with PostHog analytics integration.

Installation

npm install hydrate-beer

Or auto-install with CLI:

npx hydrate-beer init

Quick Start

Next.js App Router

// app/layout.tsx
'use client';

import { HydrateBeerProvider } from "hydrate-beer/react";

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <HydrateBeerProvider
          config={{
            posthogApiKey: process.env.NEXT_PUBLIC_HYDRATE_BEER_POSTHOG_API_KEY!,
          }}
        >
          {children}
        </HydrateBeerProvider>
      </body>
    </html>
  );
}

Next.js Pages Router

// pages/_app.tsx
import { HydrateBeerProvider } from "hydrate-beer/react";
import type { AppProps } from "next/app";

export default function App({ Component, pageProps }: AppProps) {
  return (
    <HydrateBeerProvider
      config={{
        posthogApiKey: process.env.NEXT_PUBLIC_HYDRATE_BEER_POSTHOG_API_KEY!,
      }}
    >
      <Component {...pageProps} />
    </HydrateBeerProvider>
  );
}

React (Vite, CRA, etc.)

// src/main.tsx
import { HydrateBeerProvider } from "hydrate-beer/react";
import { createRoot } from "react-dom/client";
import App from "./App";

createRoot(document.getElementById("root")!).render(
  <HydrateBeerProvider
    config={{
      posthogApiKey: import.meta.env.VITE_HYDRATE_BEER_POSTHOG_API_KEY,
    }}
  >
    <App />
  </HydrateBeerProvider>
);

Configuration

interface HydrateBeerConfig {
  // Required
  posthogApiKey: string;
  
  // Optional
  posthogHost?: string;             // Default: 'https://us.posthog.com'
  debug?: boolean;                   // Default: false
  batchSize?: number;                // Default: 10
  flushInterval?: number;            // Default: 5000 (ms)
  autoTrackRoutes?: boolean;         // Default: true
  trackComponentPerformance?: boolean; // Default: true
  trackErrors?: boolean;             // Default: true
  trackSessions?: boolean;           // Default: true
}

Environment Variables

Create a .env.local file:

# For Next.js
NEXT_PUBLIC_HYDRATE_BEER_POSTHOG_API_KEY=phc_your_api_key_here

# For Vite
VITE_HYDRATE_BEER_POSTHOG_API_KEY=phc_your_api_key_here

# For Create React App
REACT_APP_HYDRATE_BEER_POSTHOG_API_KEY=phc_your_api_key_here

Track Custom Events

'use client';

import { useHydrateBeer } from "hydrate-beer/react";

export default function MyComponent() {
  const { trackCustomEvent, trackError } = useHydrateBeer();

  const handleClick = () => {
    trackCustomEvent("button_clicked", {
      buttonName: "submit",
      timestamp: Date.now(),
    });
  };

  const handleError = (error: Error) => {
    trackError(error, {
      component: "MyComponent",
      action: "submit",
    });
  };

  return <button onClick={handleClick}>Click Me</button>;
}

What Gets Tracked Automatically

  • 📊 Page views - Every route navigation
  • 🚀 Navigation - Route transition timing
  • 🎨 Component renders - Duration and performance (configurable)
  • 🐛 Errors - Unhandled exceptions with stack traces (configurable)
  • 📈 Sessions - User session tracking (configurable)

PostHog Events

All events are sent to PostHog with the hydratebeer_ prefix:

  • hydratebeer_page_view
  • hydratebeer_navigation
  • hydratebeer_component_render
  • hydratebeer_error
  • hydratebeer_session_start
  • hydratebeer_custom

View and analyze them in your PostHog dashboard.

Privacy-First

HydrateBeer never collects:

  • ❌ User identity or personal information (PII)
  • ❌ Component props or state values
  • ❌ Form inputs or user data
  • ❌ Cookies or authentication tokens
  • ❌ IP addresses (unless PostHog GeoIP is enabled)
  • ❌ Passwords or sensitive information

Data Flow

Your App (SDK) → Tinybird Events API → Analytics Pipes → Monitor Dashboard

CLI Commands

Initialize with the CLI:

npx hydrate-beer init    # Setup PostHog integration

PostHog Setup

  1. Sign up for a free PostHog account at posthog.com
  2. Get your Project API Key from PostHog settings
  3. Run npx hydrate-beer init and enter your API key
  4. View your analytics in the PostHog dashboard

Links

Features

✅ Zero-config setup
✅ PostHog integration
✅ Framework agnostic (Next.js, React, Vite, CRA)
✅ Lightweight (<5KB gzipped)
✅ Privacy-first
✅ TypeScript support
✅ Production-ready

License

MIT