Events
The tracker emits a fixed set of named events you can subscribe to with tracker.on(event, handler), which returns an unsubscribe function, or detach later with tracker.off(event, handler). In React, prefer useEvents(), which subscribes for the component's lifetime and unsubscribes automatically on unmount.
Overview
Every event name is a member of the TrackerEventName union and falls into one of four categories: lifecycle events track the tracker instance itself, tracking events track the frame-by-frame detection process, session events track the creation and completion of recorded sessions, and the single errorevent surfaces runtime failures that don't belong to a specific method call.
Lifecycle events
Fired as the tracker itself moves through initialization, independent of any session.
readyReadyEventPayloadFires once, after init() completes successfully and the tracker's status becomes ready. Equivalent to awaiting init(), but useful when init() is called somewhere you don't control, e.g. inside a provider.
Payload
| Parameter | Type | Description |
|---|---|---|
timestampRequired | string | ISO 8601 timestamp of when the tracker finished initializing. |
Example
tracker.on("ready", ({ timestamp }) => { console.log(`Tracker ready at ${timestamp}`);}); await tracker.init();Tracking events
Fired as frame-by-frame tracking starts, stops, or the detected activity and quality change.
trackingStartedTrackingStartedEventPayloadFires when frame-by-frame movement tracking actually begins for a session — after startSession() resolves and the first camera frame has been processed. Distinct from sessionStarted, which fires immediately when the session is created.
Payload
| Parameter | Type | Description |
|---|---|---|
sessionIdRequired | string | The id of the session that began tracking. |
activityRequired | ActivityType | The activity the session started under. |
Example
tracker.on("trackingStarted", ({ sessionId, activity }) => { console.log(`Tracking ${activity} for session ${sessionId}`);});trackingStoppedTrackingStoppedEventPayloadFires whenever the tracker stops processing camera frames for the active session — including pauseSession(), stopSession(), and the tracker losing the subject unexpectedly.
Payload
| Parameter | Type | Description |
|---|---|---|
sessionIdRequired | string | The id of the session that stopped tracking. |
reasonRequired | "stopped" | "paused" | "lost" | Why tracking stopped for this session. |
Example
tracker.on("trackingStopped", ({ sessionId, reason }) => { console.log(`Session ${sessionId} stopped tracking: ${reason}`);});trackingLostTrackingLostEventPayloadFires mid-session when the tracker can no longer confidently detect the subject — poor lighting, the subject leaving the frame, or camera obstruction. The session stays active; tracking resumes automatically once conditions improve, firing trackingRestored.
Payload
| Parameter | Type | Description |
|---|---|---|
reasonRequired | string | A short machine-readable reason, e.g. "subject_out_of_frame" or "low_light". |
sinceRequired | string | ISO 8601 timestamp of when tracking was lost. |
Example
tracker.on("trackingLost", ({ reason, since }) => { showBanner(`Lost tracking (${reason}) at ${since}`);});trackingRestoredTrackingRestoredEventPayloadFires after a trackingLost event once the tracker successfully re-detects the subject and resumes producing movement data for the active session.
Payload
| Parameter | Type | Description |
|---|---|---|
timestampRequired | string | ISO 8601 timestamp of when tracking resumed. |
downtimeMsRequired | number | How long tracking was lost for, in milliseconds. |
Example
tracker.on("trackingRestored", ({ downtimeMs }) => { hideBanner(); console.log(`Tracking restored after ${downtimeMs}ms`);});movementChangedMovementChangedEventPayloadFires whenever the subject transitions between moving and stationary, independent of which specific activity is detected. Fires far more frequently than activityChanged and is best suited to lightweight UI like a "live" indicator rather than analytics.
Payload
| Parameter | Type | Description |
|---|---|---|
isMovingRequired | boolean | Whether the subject is currently in motion. |
timestampRequired | string | ISO 8601 timestamp of the transition. |
Example
tracker.on("movementChanged", ({ isMoving }) => { liveIndicator.classList.toggle("active", isMoving);});activityChangedActivityChangedEventPayloadFires whenever the tracker's detected activity type changes for the active session, e.g. walking to running. The most commonly used tracking event for driving activity-aware UI.
Payload
| Parameter | Type | Description |
|---|---|---|
fromRequired | ActivityType | The previously detected activity. |
toRequired | ActivityType | The newly detected activity. |
timestampRequired | string | ISO 8601 timestamp of the transition. |
Example
tracker.on("activityChanged", ({ from, to, timestamp }) => { console.log(`${from} -> ${to} at ${timestamp}`);});qualityChangedQualityChangedEventPayloadFires whenever the tracker's confidence in its own readings changes — driven by lighting, camera angle, and subject distance. Use it to prompt users to reposition when quality drops to "limited" or "searching".
Payload
| Parameter | Type | Description |
|---|---|---|
fromRequired | QualityLevel | The previous tracking quality. |
toRequired | QualityLevel | The new tracking quality. |
timestampRequired | string | ISO 8601 timestamp of the transition. |
Example
tracker.on("qualityChanged", ({ to }) => { if (to === "limited" || to === "searching") { showRepositionHint(); }});Session events
Fired when a session is created or finalized, mirroring startSession() and stopSession().
sessionStartedSessionFires immediately when startSession() creates a new session, with the same Session object startSession()'s promise resolves with. Useful for reacting to session creation from a listener registered elsewhere in the app, without awaiting the call yourself.
Payload
| Parameter | Type | Description |
|---|---|---|
idRequired | string | The unique id of the new session. |
startedAtRequired | string | ISO 8601 timestamp of when the session was created. |
activityRequired | ActivityType | The activity the session was started under. |
statusRequired | "recording" | "paused" | The session's status — always "recording" at creation. |
Example
tracker.on("sessionStarted", (session) => { console.log("Session started:", session.id, session.activity);});sessionEndedSessionSummaryFires when stopSession() finalizes a session, with the same SessionSummary its promise resolves with. Good place to trigger persistence or analytics without threading the summary through the call site.
Payload
| Parameter | Type | Description |
|---|---|---|
idRequired | string | The id of the session that ended. |
durationSecondsRequired | number | Total recorded duration, excluding paused time. |
activityRequired | ActivityType | The session's primary activity. |
averageQualityRequired | QualityLevel | The average tracking quality across the whole session. |
Example
tracker.on("sessionEnded", (summary) => { saveSessionToServer(summary);});Error events
Fired when the tracker encounters a runtime error outside a specific method call's promise.
errorTrackerErrorEventPayloadFires whenever the tracker encounters a runtime error outside a specific method call's promise — e.g. the camera device is unplugged mid-session. Always keep an error listener attached in production; unhandled tracker errors otherwise fail silently.
Payload
| Parameter | Type | Description |
|---|---|---|
messageRequired | string | A human-readable description of what went wrong. |
codeRequired | string | A stable machine-readable error code, e.g. "camera_disconnected". |
recoverableOptional | boolean | Whether the tracker can recover on its own without calling init() again. |
Example
tracker.on("error", ({ message, code, recoverable }) => { console.error(`[${code}] ${message}`); if (!recoverable) { tracker.destroy(); }});