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

@product-intelligence-hub/sdk-web

v0.2.0

Published

Browser SDK for Product Intelligence Hub

Readme

@product-intelligence-hub/sdk-web

Browser SDK for Product Intelligence Hub.

Installation

npm install @product-intelligence-hub/sdk-web
# or
yarn add @product-intelligence-hub/sdk-web
# or
pnpm add @product-intelligence-hub/sdk-web

Quick Start

import PIH from "@product-intelligence-hub/sdk-web";

// Initialize the SDK
const pih = PIH.init({
  apiKey: "your-api-key",
  projectId: "proj_xxx",
  environment: "production",
  tenantId: "tenant_xxx", // optional
  debug: false,
});

// Track an event
pih.track("button_clicked", {
  button_id: "signup",
  page: "/home",
});

// Identify a user
pih.identify("user_123", {
  email: "[email protected]",
  plan: "pro",
});

Configuration Options

PIH.init({
  // Required
  apiKey: string;           // Environment API key
  projectId: string;        // Project ID (proj_xxx)
  environment: string;      // Environment name

  // Optional
  apiUrl?: string;          // Ingest API URL (has default, override for self-hosted)
  tenantId?: string;        // Tenant ID for multi-tenant apps
  debug?: boolean;          // Enable debug logging (default: false)
  flushInterval?: number;   // Batch flush interval in ms (default: 10000)
  flushAt?: number;         // Flush when queue reaches this size (default: 20)
  maxQueueSize?: number;    // Max events to queue (default: 1000)
  sessionTimeout?: number;  // Session timeout in ms (default: 1800000)

  // Autocapture
  autocapture?: {
    pageViews?: boolean;    // Track page views (default: true)
    clicks?: boolean;       // Track clicks (default: false)
    formSubmissions?: boolean; // Track form submissions (default: false)
  };

  // Callbacks
  onError?: (error: PIHError) => void;
});

API

PIH.init(config)

Initialize the SDK. Returns the client instance.

pih.track(eventName, properties?, options?)

Track an event.

pih.track("purchase_completed", {
  product_id: "prod_123",
  amount: 99.99,
  currency: "USD",
});

// With options
pih.track("critical_event", { ... }, {
  immediate: true,  // Send immediately, bypass queue
  timestamp: new Date("2024-01-01"),  // Custom timestamp
});

pih.identify(userId, traits?)

Identify the current user.

pih.identify("user_123", {
  email: "[email protected]",
  name: "John Doe",
  plan: "enterprise",
});

pih.setTenant(tenantId)

Set the tenant ID for multi-tenant applications.

pih.setTenant("tenant_456");

pih.trackPageView()

Manually track a page view.

pih.trackPageView();

pih.flush()

Force flush the event queue.

await pih.flush();

pih.reset()

Reset identity (for logout).

await pih.reset();

Autocapture

Enable automatic event capture:

PIH.init({
  // ...
  autocapture: {
    pageViews: true,      // Track page_viewed on navigation
    clicks: true,         // Track element_clicked
    formSubmissions: true // Track form_submitted
  }
});

Enabling/Disabling at Runtime

// Enable
pih.enableAutocapture({ clicks: true });

// Disable
pih.disableAutocapture();

TypeScript Support

Full TypeScript support included. Types are exported from the package:

import type { PIHConfig, TrackEvent, TrackOptions } from "@product-intelligence-hub/sdk-web";

Build Outputs

  • ESM: dist/index.js
  • CommonJS: dist/index.cjs
  • Browser (IIFE): dist/index.global.js
  • TypeScript declarations: dist/index.d.ts

Related