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

upstack-node-js

v0.0.3

Published

Upstack server-side tracking SDK for Node.js

Readme

Upstack Node.js SDK

CI npm version License: MIT

Server-side tracking SDK for Node.js applications. Send tracking events from your backend to the Upstack platform.

Installation

npm install upstack-node-js

Quick Start

import { Upstack } from 'upstack-node-js';

// Initialize the client with your pixel ID
const client = Upstack.init({
  pixelId: 'your-pixel-id',
});

// Track events
await client.track({
  name: 'purchase',
  data: {
    value: 99.99,
    currency: 'USD',
    orderId: 'order-123',
    items: [
      { id: 'prod-1', name: 'Widget', price: 99.99, quantity: 1 }
    ]
  }
});

// Identify users
await client.identify({
  identity: {
    traits: {
      emails: ['[email protected]'],
      firstNames: ['John'],
      lastNames: ['Doe']
    }
  }
});

API Reference

Upstack.init(config)

Initialize a new Upstack client.

const client = Upstack.init({
  pixelId: 'your-pixel-id',     // Required: Your Upstack pixel ID
  timeout: 10000,                // Optional: Request timeout in ms (default: 10000)
  debug: false                   // Optional: Enable debug logging (default: false)
});

client.track(options)

Send a tracking event.

await client.track({
  name: 'purchase',              // Required: Event name
  data: {                        // Optional: Event data
    value: 99.99,
    currency: 'USD',
    orderId: 'order-123',
    items: [...]
  },
  context: {                     // Optional: Event context
    identity: {
      traits: {
        emails: ['[email protected]']
      }
    }
  }
});

Standard Event Names

| Event Name | Description | |------------|-------------| | page_view | User viewed a page | | view_content | User viewed a product/content | | add_to_cart | User added item to cart | | initiate_checkout | User started checkout | | add_payment_info | User added payment information | | purchase | User completed purchase | | lead | User submitted a lead form | | sign_up | User signed up | | login | User logged in | | search | User performed a search |

client.identify(options)

Identify a user. This stores the identity context for all subsequent track() calls.

await client.identify({
  identity: {
    traits: {
      emails: ['[email protected]'],
      phones: ['+1234567890'],
      firstNames: ['John'],
      lastNames: ['Doe'],
      addresses: [{
        city: 'New York',
        country: 'US',
        zip: '10001'
      }]
    }
  },
  properties: {                  // Optional: Additional context
    campaign: {
      source: 'google',
      medium: 'cpc'
    }
  }
});

client.getContext()

Get the currently stored context.

const context = client.getContext();
console.log(context.identity?.traits?.emails);

client.clearContext()

Clear the stored context.

client.clearContext();

Event Data Reference

Purchase Event

await client.track({
  name: 'purchase',
  data: {
    orderId: 'order-123',
    value: 149.99,
    currency: 'USD',
    tax: 12.50,
    shipping: 5.99,
    discount: 10.00,
    coupon: 'SAVE10',
    items: [
      {
        id: 'prod-123',
        name: 'Premium Widget',
        sku: 'WIDGET-001',
        price: 149.99,
        quantity: 1,
        category: 'Electronics',
        brand: 'WidgetCo'
      }
    ]
  }
});

Add to Cart Event

await client.track({
  name: 'add_to_cart',
  data: {
    value: 29.99,
    currency: 'USD',
    items: [
      {
        id: 'prod-456',
        name: 'Basic Gadget',
        price: 29.99,
        quantity: 1
      }
    ]
  }
});

Error Handling

The SDK throws UpstackError for all errors:

import { Upstack, UpstackError } from 'upstack-node-js';

try {
  await client.track({ name: 'purchase', data: { value: 99.99 } });
} catch (error) {
  if (error instanceof UpstackError) {
    console.error('Upstack error:', error.message);
    console.error('Error code:', error.code);       // e.g., 'NETWORK_ERROR', 'TIMEOUT'
    console.error('Status code:', error.statusCode); // HTTP status if applicable
  }
}

Error Codes

| Code | Description | |------|-------------| | INVALID_CONFIG | Invalid client configuration | | NETWORK_ERROR | Network request failed | | TIMEOUT | Request timed out | | TRACK_FAILED | Failed to track event | | IDENTIFY_FAILED | Failed to identify user |

TypeScript Support

The SDK is written in TypeScript and includes full type definitions:

import { 
  Upstack, 
  UpstackClient,
  TrackingEvent,
  TrackingEventData,
  EventContext,
  EventIdentity,
  ClientConfig,
  TrackOptions,
  IdentifyOptions
} from 'upstack-node-js';

Environment Configuration

The SDK reads process.env.STAGE at runtime to select the API URL:

| Stage | API URL | |-------|---------| | dev2 | https://dev2-api.upstackdata.io | | qa2 | https://qa2-api.upstackdata.io | | prod2 (default) | https://cfapi.upstackdata.io |

If STAGE is not set, the SDK defaults to prod2.

Requirements

  • Node.js >= 20.0.0
  • Native fetch support (Node.js 18+ or polyfill)

License

MIT