Tracker Analytics SDK

Learn how to set up and use OpenReplay tracker analytics SDK

Tracker Analytics SDK

Learn how to set up the OpenReplay tracker analytics SDK.

The analytics SDK is opt-in. It is only instantiated when you pass analytics.active to the tracker constructor — until then tracker.analytics is null and tracker.track() is a no-op.

import Tracker from '@openreplay/tracker'

const tracker = new Tracker({
  projectKey: "YOUR_PROJECT_KEY",
  analytics: { active: true },
})

tracker.start()
  • active: boolean Turns the analytics SDK on. Default: false.
  • ingestPoint?: string Endpoint analytics batches are sent to. Self-hosted deployments only — on OpenReplay Cloud this is ignored and https://api.openreplay.com/ingest is used. Defaults to the tracker’s ingestPoint.

To learn more about managing your analytics data in the OpenReplay UI, visit Data Management.

// Identify a user with an id (e.g. email, username, etc.)
tracker.analytics.identify(userId: string): void
// same as
tracker.analytics.people.identify(userId)

// Add event to batch with option to send it immediately
tracker.analytics.track(eventName: string, tempProperties?: Record<string, any>, options?: { send_immediately: boolean })
// same as
tracker.analytics.events.track(eventName, tempProperties, options)

// Clear user id, people properties and super properties, and stop the batcher
tracker.analytics.reset(): void

These live on the tracker itself, so they are safe to call without reaching into tracker.analytics (they are no-ops while analytics is disabled):

// Same as tracker.analytics.track(...)
tracker.track(eventName: string, properties?: Record<string, any>, options?: { send_immediately: boolean })

// Sets the replay's user ID *and* calls analytics.people.identify() with it
tracker.setUserID(id: string): void
tracker.identify(id: string): void // alias of setUserID

// Send analytics events under your own token, without session recording
tracker.setAnalyticsToken(token: string): void

Clears the identified user (including the persistent device id), all people properties, all super properties, and stops the batcher. Call it on logout.

tracker.analytics.reset()

If you encounter any issues, connect to our Slack or check out our Forum and get help from our community.