Skip to main content
The Staminads Web SDK captures session data, tracks engagement, and sends events to your workspace. It’s lightweight (~18KB gzipped), privacy-focused, and works across all modern browsers.

Installation

Add the configuration and script to your HTML:
Place the config script in the <head> and the SDK script before the closing </body> tag for optimal performance.

Configuration

Set window.StaminadsConfig before loading the SDK:

Configuration Options

Cross-Domain Tracking

By default, sessions are isolated per domain. When a visitor navigates from blog.example.com to shop.example.com, the SDK would create a new session on the shop domain — losing the connection to the original visit. Cross-domain tracking solves this by sharing session identity across domains, so you get:
  • Accurate session counts — One visitor journey = one session, not multiple
  • Complete user paths — See the full journey from blog article to checkout
  • Correct attribution — UTM parameters and referrer data stay with the session
All domains must use the same workspace_id and have the SDK installed with the same crossDomains configuration.

How It Works

  1. When a user clicks a link to a configured domain, the SDK appends a _stm parameter with encrypted session data
  2. On the target domain, the SDK reads the parameter and continues the same session
  3. The parameter is stripped from the URL automatically (if crossDomainStripParams: true)

Manual URL Decoration

For programmatic navigation, use decorateUrl():
Cross-domain linking only works for domains in the crossDomains array. Links to other domains are not decorated.

API Reference

Session Information

Page Views

Page views are tracked automatically, but you can trigger them manually for SPAs:

Goals

Track conversions and goals with optional value:

Custom Dimensions

Set custom dimensions (1-10) for advanced segmentation. There are two ways to set dimensions:

Via URL Parameters (Automatic)

Custom dimensions can be set via URL parameters stm_1 through stm_10. They are automatically captured when the SDK initializes:
This is useful for:
  • Campaign tracking links
  • A/B test variant assignment
  • Affiliate tracking
  • Any scenario where you want to pass dimension values via URL
Priority rule: Existing dimension values take priority over URL parameters. If a dimension is already set (e.g., from a previous page in the session), the URL parameter will NOT overwrite it.

Via JavaScript (Programmatic)

Custom dimensions are sent as stm_1 through stm_10 in events. Label them in Workspace Settings > Custom Dimensions for readable reports.

User Identification

Associate sessions with authenticated users for cross-device tracking and user-level analytics:
Consent required: Linking analytics data to user identifiers requires explicit user consent under GDPR, ePrivacy Directive, and similar privacy regulations. Only call setUserId() after obtaining valid consent for analytics tracking. Ensure your privacy policy discloses this data collection.
Set the user ID immediately after login (and consent) to ensure all subsequent events are associated with the user.

Control Methods

Debugging

Automatic Tracking

The SDK automatically tracks the following without any code:

UTM Parameters

UTM parameters are automatically captured from URLs:

Ad Click IDs

The SDK automatically detects and captures ad network click IDs:

Focus State Tracking

The SDK tracks engagement using a focus state machine: Only FOCUSED time counts toward engagement duration, giving you accurate TimeScore calculations.

Offline Support

Events are queued when offline and sent when connectivity returns:
  • Queue holds up to 50 events
  • Events expire after 24 hours
  • Uses Beacon API with Fetch fallback
  • Handles Safari Private Mode gracefully

Privacy & Compliance

  • No cookies — Uses localStorage with memory fallback
  • No PII — Does not collect personal identifiable information
  • Bot filtering — Automatically excludes crawlers and bots