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

churnsignal-sdk

v1.0.2

Published

Track user behavior and predict churn before it happens. Official ChurnSignal SDK.

Readme

churnsignal

Track user behavior and predict churn before it happens.

npm version npm downloads license TypeScript

ChurnSignal detects at-risk users in your SaaS app and alerts you before they cancel. This is the official JavaScript/TypeScript SDK.


Installation

npm install churnsignal
# or
yarn add churnsignal
# or
pnpm add churnsignal

Quick Start

import { ChurnSignal } from 'churnsignal'

// 1. Initialize once (app root / layout)
ChurnSignal.init({
  apiKey: process.env.NEXT_PUBLIC_CHURNSIGNAL_KEY!
})

// 2. Track events anywhere
ChurnSignal.track({
  userId: user.id,
  event: 'login'
})

// 3. Identify users (optional but recommended)
ChurnSignal.identify({
  userId: user.id,
  email: user.email,
  metadata: {
    plan: 'pro',
    country: 'US'
  }
})

Framework Examples

Next.js (App Router)

// app/layout.tsx
import { ChurnSignal } from 'churnsignal'

ChurnSignal.init({
  apiKey: process.env.NEXT_PUBLIC_CHURNSIGNAL_KEY!
})

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return <html><body>{children}</body></html>
}
// Track on user actions
import { ChurnSignal } from 'churnsignal'

ChurnSignal.track({ userId: user.id, event: 'export_csv' })
ChurnSignal.track({ userId: user.id, event: 'plan_downgraded', metadata: { from: 'pro', to: 'free' } })

Node.js / Express

import { ChurnSignal } from 'churnsignal'

ChurnSignal.init({ apiKey: process.env.CHURNSIGNAL_KEY! })

app.post('/auth/login', async (req, res) => {
  const user = await login(req.body)
  ChurnSignal.track({ userId: user.id, event: 'login' })
  res.json({ user })
})

API

ChurnSignal.init(config)

Initialize the SDK. Call this once at app startup before any track() or identify() calls.

| Option | Type | Default | Description | |---|---|---|---| | apiKey | string | required | Your ChurnSignal API key (cs_live_...) | | debug | boolean | false | Log events to console | | disabled | boolean | false | Disable all tracking | | flushInterval | number | 5000 | Batch send interval in ms | | maxRetries | number | 3 | Retry attempts on network failure |


ChurnSignal.track(options)

Track a user event.

| Option | Type | Required | Description | |---|---|---|---| | userId | string | ✓ | Your user's unique ID | | event | string | ✓ | Event name (snake_case recommended) | | metadata | object | — | Any extra JSON data (max 5KB) |

High-signal events to track:

// These most affect churn scoring
ChurnSignal.track({ userId, event: 'login' })
ChurnSignal.track({ userId, event: 'logout' })
ChurnSignal.track({ userId, event: 'plan_downgraded' })
ChurnSignal.track({ userId, event: 'payment_failed' })
ChurnSignal.track({ userId, event: 'support_ticket_opened' })
ChurnSignal.track({ userId, event: 'export_data' })
ChurnSignal.track({ userId, event: 'onboarding_completed' })

ChurnSignal.identify(options)

Set or update user properties. Call on signup or when user properties change.

| Option | Type | Required | Description | |---|---|---|---| | userId | string | ✓ | Your user's unique ID | | email | string | — | User's email address | | metadata | object | — | Any user properties |

ChurnSignal.identify({
  userId: 'user_123',
  email: '[email protected]',
  metadata: {
    plan: 'pro',
    company: 'Acme Corp',
    country: 'US',
    signupSource: 'google'
  }
})

ChurnSignal.reset()

Clear config and stop tracking. Useful for logout flows.

// On user logout
ChurnSignal.reset()

Debug Mode

ChurnSignal.init({
  apiKey: 'cs_live_xxx',
  debug: process.env.NODE_ENV === 'development'
})

// Now all events are logged to console:
// [ChurnSignal] track { userId: 'u1', event: 'login' }

Disabling Tracking (GDPR / Opt-out)

// Disable for users who opted out
ChurnSignal.init({
  apiKey: 'cs_live_xxx',
  disabled: !user.analyticsConsent
})

TypeScript

Full TypeScript support included. No @types package needed.

import { ChurnSignal, ChurnSignalConfig, TrackOptions } from 'churnsignal'

How It Works

  1. You call track() from your app
  2. Events are batched and sent to api.churnsignal.io
  3. ChurnSignal writes events to your own Supabase database (BYOD model)
  4. Every 6 hours, ChurnSignal recalculates churn scores for all your users
  5. When a user's score crosses your threshold → you get a Slack/email alert

Your data never leaves your infrastructure.


Links


License

MIT © ChurnSignal