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

@bklit/sdk

v1.0.1

Published

A lightweight analytics SDK for tracking page views, sessions, and user behavior via WebSocket.

Readme

Bklit Analytics SDK

A lightweight analytics SDK for tracking page views, sessions, and user behavior via WebSocket.

⚠️ Upgrading from v0.x? See the Migration Guide below.

Installation

npm install @bklit/sdk
# or
pnpm add @bklit/sdk

Quick Start

Vanilla JavaScript / React

import { initBklit } from "@bklit/sdk";

initBklit({
  projectId: "your-project-id",
  apiKey: "your-api-key",
  debug: true, // Optional - enables console logging
});

Next.js

For Next.js applications, use the BklitComponent:

import { BklitComponent } from "@bklit/sdk/nextjs";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html>
      <body>
        <BklitComponent
          projectId="your-project-id"
          apiKey="your-api-key"
          debug={process.env.NODE_ENV === "development"}
        />
        {children}
      </body>
    </html>
  );
}

Get your projectId and apiKey from your Bklit Dashboard.

Configuration Options

BklitComponent (Next.js)

Props:

  • projectId (string, required) - Your unique project identifier
  • apiKey (string, optional) - Your API authentication token
  • wsHost (string, optional) - WebSocket server URL. Defaults to wss://bklit.ws in production, ws://localhost:8080 in development
  • environment (string, optional) - Environment mode: "development" or "production". Defaults to "production"
  • debug (boolean, optional) - Enable debug logging. Defaults to false

initBklit(options)

Required Parameters:

  • projectId (string) - Your unique project identifier from the Bklit dashboard
  • apiKey (string) - Your API authentication token from the Bklit dashboard

Optional Parameters:

  • wsHost (string) - WebSocket server URL. Defaults to wss://bklit.ws in production, ws://localhost:8080 in development
  • environment (string) - Set to "development" for local testing. Defaults to "production"
  • debug (boolean) - Enable detailed console logging. Defaults to false

Example with All Options

initBklit({
  projectId: "your-project-id",
  apiKey: "your-api-key",
  wsHost: "wss://bklit.ws", // Optional - auto-detected
  environment: "production", // Optional
  debug: false, // Optional
});

How It Works

The SDK establishes a WebSocket connection to track analytics in real-time:

  1. Persistent Connection - Opens WebSocket to wss://bklit.ws on initialization
  2. Automatic Tracking - Sends pageviews and navigation events over WebSocket
  3. Instant Session End - Sessions end automatically when the browser tab closes (WebSocket disconnect)
  4. Auto-Reconnect - Reconnects automatically with exponential backoff if connection drops
  5. Message Queuing - Queues events when connection is not ready

API Reference

trackPageView()

Manually track a page view. Usually not needed as the SDK auto-tracks navigation.

import { trackPageView } from "@bklit/sdk";

trackPageView();

trackEvent(trackingId, eventType, metadata, triggerMethod)

Track custom events like button clicks, form submissions, etc.

import { trackEvent } from "@bklit/sdk";

trackEvent(
  "cta-button", // tracking ID
  "click", // event type
  { buttonText: "Sign Up", position: "hero" }, // metadata (optional)
  "automatic" // trigger method (optional)
);

Console Logging

When debug: true is enabled, the SDK provides detailed console logs:

  • 🔌 Bklit SDK: Connecting to WebSocket
  • ✅ Bklit SDK: WebSocket connected
  • 🚀 Bklit SDK: Message sent via WebSocket
  • 📦 Bklit SDK: Message queued (WebSocket not ready)
  • 🔄 Bklit SDK: Reconnecting...

Error messages (using console.error and console.warn) always appear regardless of the debug setting.

Architecture

Browser SDK → WebSocket (wss://bklit.ws) → Queue → ClickHouse
     ↓                                         ↓
Auto-reconnect                          Real-time Dashboard
  • Sub-second latency for real-time analytics
  • Instant session tracking - Sessions appear/disappear immediately
  • Reliable - Browser handles WebSocket cleanup automatically

Migrating from v0.x

Breaking Changes in v1.0.0

v1.0.0 migrates from HTTP to WebSocket architecture. This requires a configuration change:

Before (v0.x):

import { initBklit } from "@bklit/sdk";

initBklit({
  projectId: "your-project-id",
  apiKey: "your-api-key",
  apiHost: "https://app.bklit.com/api/track",  // ❌ No longer used
});

After (v1.0.0):

import { initBklit } from "@bklit/sdk";

initBklit({
  projectId: "your-project-id",
  apiKey: "your-api-key",
  wsHost: "wss://bklit.ws:8080",  // Optional - auto-detected in most cases
});

Or simplest (recommended):

initBklit({
  projectId: "your-project-id",
  apiKey: "your-api-key",
  // wsHost auto-detected based on environment
});

For Next.js Apps

Before (v0.x):

<BklitComponent
  projectId="..."
  apiKey="..."
  apiHost="https://app.bklit.com/api/track"  // ❌ Remove this
/>

After (v1.0.0):

<BklitComponent
  projectId="..."
  apiKey="..."
  wsHost="wss://bklit.ws:8080"  // Optional - auto-detected
/>

Or simplest:

<BklitComponent
  projectId="..."
  apiKey="..."
  // wsHost auto-detected
/>

What Changed

  • HTTP → WebSocket: Persistent connection instead of HTTP requests
  • Instant session ending: <1 second instead of 30s-4min
  • Auto-reconnection: Handles network issues gracefully
  • Removed: endSession() function (automatic now)

Need Help?

See the full CHANGELOG or open an issue.

License

MIT