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

@saas-maker/posthog-client

v0.1.0

Published

Typed PostHog wrapper — React provider, hooks, and event registry for the Foundry stack.

Readme

@saas-maker/posthog-client

Typed PostHog wrapper for Foundry-stack apps. Browser + server clients, React provider/hook, and a .posthog-events.json schema validator.

Install

pnpm add @saas-maker/posthog-client

Set env vars:

NEXT_PUBLIC_POSTHOG_KEY=phc_xxxxxxxxxxxx
NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com  # optional

Browser — Next.js App Router

// app/providers.tsx
'use client';
import { PostHogProvider } from '@saas-maker/posthog-client';

export function Providers({ children }) {
  return <PostHogProvider>{children}</PostHogProvider>;
}
// app/some-page.tsx
'use client';
import { usePostHog, track } from '@saas-maker/posthog-client';

export function Button() {
  const ph = usePostHog();
  return (
    <button onClick={() => track('feedback_submitted', { project_id: 'p1' })}>
      Send
    </button>
  );
}

Typed event registry

Define your events once, get autocomplete + payload type-checking everywhere:

// posthog-events.d.ts
import type { BaseEventMap } from '@saas-maker/posthog-client';

export interface AppEvents extends BaseEventMap {
  feedback_submitted: { project_id: string; type: 'bug' | 'feature' };
  user_signed_in: { method: 'google' | 'github' };
}
import { track } from '@saas-maker/posthog-client';
import type { AppEvents } from './posthog-events';

track<AppEvents>('feedback_submitted', { project_id: 'p1', type: 'bug' });
// ✗ track<AppEvents>('feedback_submitted', { project_id: 1 }); // type error

Server — Next.js route handler / Workers

// app/api/track/route.ts
import { createPostHogServer, trackServer, flushServer } from '@saas-maker/posthog-client/server';

createPostHogServer({ apiKey: process.env.POSTHOG_KEY! });

export async function POST() {
  trackServer('user_signed_in', { distinctId: 'user-1', properties: { method: 'google' } });
  await flushServer();
  return Response.json({ ok: true });
}

Schema validator (.posthog-events.json)

Validate the foundry event registry from CI / pre-push:

import { readFileSync } from 'node:fs';
import { validatePostHogSchema } from '@saas-maker/posthog-client/schema';

const raw = JSON.parse(readFileSync('.posthog-events.json', 'utf-8'));
const result = validatePostHogSchema(raw);
if (!result.ok) {
  console.error(result.errors.join('\n'));
  process.exit(1);
}

Generate the typed EventMap interface from the validated registry:

import { generateEventMap } from '@saas-maker/posthog-client/schema';
console.log(generateEventMap(result.entries));

API surface

| Symbol | Where | Notes | |---|---|---| | <PostHogProvider> | . | React provider (client-only) | | usePostHog() | . | Hook returning the live PostHog instance | | initPostHog(opts) | . | Manual init for non-React apps | | track(name, props) | . | Browser capture | | identify(id, props) | . | Browser identify | | createPostHogServer(opts) | /server | posthog-node instance | | trackServer(name, args) | /server | Server capture | | flushServer() | /server | Flush before response ends | | validatePostHogSchema(raw) | /schema | Validate registry JSON | | generateEventMap(entries) | /schema | Codegen typed EventMap |