Skip to main content
The Upstack JavaScript SDK provides client-side event tracking, user identification, and session management. It captures browsing behavior, resolves user identity across devices, and forwards events to your configured destinations.
Important: The correct global is window._upstack() (with underscore), not window.upstack(). Older documentation may reference the incorrect name.

Installation

The Upstack pixel is distributed via CDN, not npm. Add this snippet to your site’s <head>:
Why this works:
  1. The inline script defines _upstack() as a function that pushes calls to a queue
  2. Calls made before the SDK loads are queued — no events are lost
  3. Once the SDK loads, it processes the queue and replaces _upstack() with the real implementation
  4. Safe to call immediately without checking load status

API Overview


Queue Commands

These methods can be called via _upstack('command', ...) before or after the SDK loads.

init(pixelId)

Initialize the Upstack pixel with your pixel ID.
Parameters:
Queue Limitation: When using _upstack('init', pixelId, identityTraits, scriptSource), only pixelId is passed to the init function. The identityTraits and scriptSource parameters are dropped by the queue processor.For full init with identity traits, use the direct client after the script loads.
Examples:

page(eventData?)

Track a page view. Automatically captures page URL, title, referrer, and path.
Parameters: Auto-captured properties:
  • page_url — Current page URL
  • page_title — Document title
  • page_referrer — Referring URL
  • page_path — URL path
Examples:

track(eventName, eventData?, …)

Track a custom event. Supports 7 positional parameters plus a shorthand for useBeacon.
Parameters: Shorthand for useBeacon: When the 4th argument is an object with useBeacon, it’s treated as options:
Examples:

identify(userId?, data?)

Associate user identity with the current session. Used for cross-device tracking and destination matching.
Parameters:
Important: emails and phones are arrays, not single values. This supports users with multiple contact methods.
Examples:

metric(metricName, metricValue, metricData?, metricId?)

Send a custom metric value.
Currently Disabled: The metric() method is routed through the queue but returns null — metric forwarding is disabled in the public SDK. This method exists for future use.
Parameters: Example:

reset()

Clear identity, session data, event listeners, and hooks. Call when a user logs out.
Example:

Direct Client Methods

These methods are only available via window._upsClient after initialization completes. They cannot be called through the _upstack() queue.

isKnown()

Check if the current user has been identified.
Returns: Promise resolving to true if the user has been identified, false otherwise.
Direct Client Only: This method is NOT available via the _upstack() queue. You must call it directly on window._upsClient.
Example:

getUpstackId()

Retrieve the Upstack identity object for the current user.
Returns: Promise resolving to an UpstackId object (not a string).
Direct Client Only: This method is NOT available via the _upstack() queue. You must call it directly on window._upsClient.Return Type: Returns an object with identity fields, not a single string ID.
Example:

Waiting for SDK Ready

When using direct client methods, ensure the SDK has loaded:

Common Patterns

SPA Navigation Tracking

Track page views on route changes in single-page applications:

E-commerce Funnel

Track the complete customer journey:

Page Exit Tracking with Beacon

Reliably track time on page even when the user closes the tab:

Form Submission Tracking

Capture leads from newsletter signups:

TypeScript Support

Add type declarations for TypeScript projects:

Methods NOT Available

The following methods are not implemented in the public SDK:
  • consent — Not implemented
  • group — Not implemented (stub exists)
  • screen — Not implemented (stub exists)
  • alias — Not implemented (stub exists)
Internal methods (do not call directly):
  • notify — Internal hook messaging
  • postInit — Internal post-initialization

Pixel Setup

Installation guide for non-Shopify websites and SPAs.

Standard Events

Complete reference for all standard events with JavaScript snippets.

Properties & Context

Reference for item arrays, customer data, and auto-captured fields.

Custom Events

Create events beyond the standard taxonomy for your needs.

Identity Resolution

How identify() connects sessions to customer profiles.

Shopify Automatic Tracking

Events tracked automatically on Shopify stores.