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

@altertable/altertable-react

v1.0.6

Published

React SDK to capture and send events to Altertable.

Readme

@altertable/altertable-react

React SDK for capturing and sending analytics events to Altertable with type-safe funnel tracking.

Installation

npm install @altertable/altertable-js @altertable/altertable-react
# or
pnpm add @altertable/altertable-js @altertable/altertable-react
# or
yarn add @altertable/altertable-js @altertable/altertable-react
# or
bun add @altertable/altertable-js @altertable/altertable-react

Quick Start

import {
  AltertableProvider,
  useAltertable,
} from '@altertable/altertable-react';
import { altertable } from '@altertable/altertable-js';

// Initialize the core SDK
altertable.init('YOUR_API_KEY');

function App() {
  return (
    <AltertableProvider client={altertable}>
      <SignupPage />
    </AltertableProvider>
  );
}

function SignupPage() {
  const { track } = useAltertable();

  function handleStart() {
    track('Signup Started', { source: 'homepage' });
  }

  function handleSubmit(email: string) {
    track('Signup Submitted', { email });
  }

  return (
    <div>
      <button onClick={() => handleStart()}>Start Signup</button>
      <button onClick={() => handleSubmit('[email protected]')}>
        Submit
      </button>
    </div>
  );
}

[!NOTE]

For server-side rendering (SSR), initialize in a useEffect():

import { useEffect } from 'react';
import { altertable } from '@altertable/altertable-js';
import { AltertableProvider } from '@altertable/altertable-react';

function App() {
  useEffect(() => {
    altertable.init('YOUR_API_KEY');
  }, []);

  return (
    <AltertableProvider client={altertable}>
      <SignupPage />
    </AltertableProvider>
  );
}

Features

  • Automatic page view tracking – Captures page views automatically
  • Session management – Handles anonymous and session IDs automatically
  • Event queuing – Queues events when offline or consent is pending
  • Privacy compliance – Built-in tracking consent management
  • Multiple storage options – localStorage, cookies, or both
  • Type-safe funnel tracking – Define funnel steps with TypeScript for compile-time safety
  • React Hooks – Easy-to-use Hooks for tracking events and managing funnels
  • Context provider – Share Altertable instance across your React component tree
  • Zero dependencies – Only depends on React and the core Altertable SDK

API Reference

Components

<AltertableProvider>

Provides the Altertable client to the React component tree.

Props:

| Parameter | Type | Required | Description | | ---------- | ----------------------------------------------------------------------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | client | Altertable | Yes | The Altertable client instance (see core SDK API Reference) | | children | ReactNode | Yes | React children |

Example:

import { AltertableProvider } from '@altertable/altertable-react';
import { altertable } from '@altertable/altertable-js';

altertable.init('YOUR_API_KEY');

function App() {
  return (
    <AltertableProvider client={altertable}>
      <YourApp />
    </AltertableProvider>
  );
}

Hooks

useAltertable<TFunnelMapping>()

Returns an object with tracking methods and funnel utilities.

Type Parameters:

| Parameter | Type | Required | Description | | ---------------- | --------------------------------- | -------- | ------------------------------------------------------ | | TFunnelMapping | FunnelMapping | No | Type mapping of funnel names to their step definitions |

Returns:

| Property | Type | Description | | -------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | | identify | (userId: string, traits?: UserTraits) => void | Identify a user | | page | (url: string) => void | Manually track a page view (use only when autoCapture is false) | | reset | (options?: { resetDeviceId?: boolean }) => void | Resets the current identity context so future events are not associated with the previous user | | alias | (newUserId: string) => void | Link a new ID to the current identity | | updateTraits | (traits: UserTraits) => void | Update user traits | | configure | (updates: Partial<AltertableConfig>) => void | Update configuration | | getTrackingConsent | () => TrackingConsentType | Get current consent state | | selectFunnel | (funnelName: keyof TFunnelMapping) => { track: FunnelTracker } | Get funnel-specific tracker |

Example:

function MyComponent() {
  const { track, identify, selectFunnel } = useAltertable<MyFunnelMapping>();

  function handleClick() {
    track('Button Clicked', { button: 'signup' });
  }

  function handleLogin(userId: string) {
    identify(userId, { email: '[email protected]' });
  }

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

[!NOTE]

Page Tracking: By default, Altertable automatically captures page views. Only use page() when you've disabled auto-capture:

// Initialize with auto-capture disabled
altertable.init('YOUR_API_KEY', { autoCapture: false });

function MyComponent() {
  const { page } = useAltertable();

  // Now you must manually track page views
  function handleNavigation(nextUrl: string) {
    page(nextUrl);
  }
}

Why use auto-capture (default)?

  • No manual tracking required
  • Handles browser navigation events (popstate, hashchange)
  • Consistent tracking across all page changes

When to use page():

  • Custom routing that doesn't trigger browser events
  • Virtual page views that don't trigger URL changes (modals, step changes)
  • Server-side tracking where auto-capture isn't available

selectFunnel(funnelName)

Returns a type-safe tracker for a specific funnel.

Parameters:

| Parameter | Type | Required | Description | | ------------ | ---------------------- | -------- | ------------------------------- | | funnelName | keyof TFunnelMapping | Yes | The name of the funnel to track |

Returns:

| Property | Type | Description | | ----------- | ----------------------------------------------------------------------- | ----------------------------- | | trackStep | (stepName: FunnelStepName, properties?: FunnelStepProperties) => void | Type-safe funnel step tracker |

Example:

import {
  type FunnelMapping,
  useAltertable,
} from '@altertable/altertable-react';

interface SignupFunnelMapping extends FunnelMapping {
  signup: [
    { name: 'Signup Started'; properties: { source: string } },
    { name: 'Signup Completed'; properties: { userId: string } },
  ];
}

function SignupPage() {
  const { selectFunnel } = useAltertable<SignupFunnelMapping>();
  const { trackStep } = selectFunnel('signup');

  function handleStart() {
    trackStep('Signup Started', { source: 'homepage' });
  }

  function handleComplete(userId: string) {
    trackStep('Signup Completed', { userId });
  }

  return (
    <div>
      <button
        onClick={() => {
          handleStart();
        }}
      >
        Start
      </button>
      <button
        onClick={() => {
          handleComplete('u_01jza857w4f23s1hf2s61befmw');
        }}
      >
        Complete
      </button>
    </div>
  );
}

Types

AltertableConfig

Configuration options for the Altertable SDK. See the core SDK documentation for full details.

FunnelMapping

Type mapping of funnel names to their step definitions.

type FunnelMapping = Record<FunnelName, readonly FunnelStep[]>;

Example:

import { type FunnelMapping } from '@altertable/altertable-react';

interface MyFunnelMapping extends FunnelMapping {
  signup: [
    {
      name: 'Signup Started';
      properties: { source: string };
    },
    {
      name: 'Signup Completed';
      properties: { userId: string };
    },
  ];
  checkout: [
    {
      name: 'Cart Viewed';
      properties: { itemCount: number };
    },
    {
      name: 'Purchase Completed';
      properties: { orderId: string; amount: number };
    },
  ];
}

FunnelStep

Definition of a single funnel step.

type FunnelStep = {
  name: string;
  properties?: FunnelStepProperties;
};

| Property | Type | Required | Description | | ------------ | ---------------------- | -------- | --------------------------------- | | name | string | Yes | The name of the funnel step | | properties | FunnelStepProperties | No | Expected properties for this step |

FunnelTracker

Type-safe tracker for a specific funnel.

type FunnelTracker = {
  trackStep: (
    stepName: FunnelStepName,
    properties?: FunnelStepProperties
  ) => void;
};

License

MIT