BT

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.

readyReadyEventPayload

Fires 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

ParameterTypeDescription
timestampRequired
stringISO 8601 timestamp of when the tracker finished initializing.

Example

ready.tsTypeScript
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.

trackingStartedTrackingStartedEventPayload

Fires 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

ParameterTypeDescription
sessionIdRequired
stringThe id of the session that began tracking.
activityRequired
ActivityTypeThe activity the session started under.

Example

tracking-started.tsTypeScript
tracker.on("trackingStarted", ({ sessionId, activity }) => {  console.log(`Tracking ${activity} for session ${sessionId}`);});
trackingStoppedTrackingStoppedEventPayload

Fires whenever the tracker stops processing camera frames for the active session — including pauseSession(), stopSession(), and the tracker losing the subject unexpectedly.

Payload

ParameterTypeDescription
sessionIdRequired
stringThe id of the session that stopped tracking.
reasonRequired
"stopped" | "paused" | "lost"Why tracking stopped for this session.

Example

tracking-stopped.tsTypeScript
tracker.on("trackingStopped", ({ sessionId, reason }) => {  console.log(`Session ${sessionId} stopped tracking: ${reason}`);});
trackingLostTrackingLostEventPayload

Fires 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

ParameterTypeDescription
reasonRequired
stringA short machine-readable reason, e.g. "subject_out_of_frame" or "low_light".
sinceRequired
stringISO 8601 timestamp of when tracking was lost.

Example

tracking-lost.tsTypeScript
tracker.on("trackingLost", ({ reason, since }) => {  showBanner(`Lost tracking (${reason}) at ${since}`);});
trackingRestoredTrackingRestoredEventPayload

Fires after a trackingLost event once the tracker successfully re-detects the subject and resumes producing movement data for the active session.

Payload

ParameterTypeDescription
timestampRequired
stringISO 8601 timestamp of when tracking resumed.
downtimeMsRequired
numberHow long tracking was lost for, in milliseconds.

Example

tracking-restored.tsTypeScript
tracker.on("trackingRestored", ({ downtimeMs }) => {  hideBanner();  console.log(`Tracking restored after ${downtimeMs}ms`);});
movementChangedMovementChangedEventPayload

Fires 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

ParameterTypeDescription
isMovingRequired
booleanWhether the subject is currently in motion.
timestampRequired
stringISO 8601 timestamp of the transition.

Example

movement-changed.tsTypeScript
tracker.on("movementChanged", ({ isMoving }) => {  liveIndicator.classList.toggle("active", isMoving);});
activityChangedActivityChangedEventPayload

Fires 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

ParameterTypeDescription
fromRequired
ActivityTypeThe previously detected activity.
toRequired
ActivityTypeThe newly detected activity.
timestampRequired
stringISO 8601 timestamp of the transition.

Example

activity-changed.tsTypeScript
tracker.on("activityChanged", ({ from, to, timestamp }) => {  console.log(`${from} -> ${to} at ${timestamp}`);});
qualityChangedQualityChangedEventPayload

Fires 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

ParameterTypeDescription
fromRequired
QualityLevelThe previous tracking quality.
toRequired
QualityLevelThe new tracking quality.
timestampRequired
stringISO 8601 timestamp of the transition.

Example

quality-changed.tsTypeScript
tracker.on("qualityChanged", ({ to }) => {  if (to === "limited" || to === "searching") {    showRepositionHint();  }});

Session events

Fired when a session is created or finalized, mirroring startSession() and stopSession().

sessionStartedSession

Fires 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

ParameterTypeDescription
idRequired
stringThe unique id of the new session.
startedAtRequired
stringISO 8601 timestamp of when the session was created.
activityRequired
ActivityTypeThe activity the session was started under.
statusRequired
"recording" | "paused"The session's status — always "recording" at creation.

Example

session-started.tsTypeScript
tracker.on("sessionStarted", (session) => {  console.log("Session started:", session.id, session.activity);});
sessionEndedSessionSummary

Fires 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

ParameterTypeDescription
idRequired
stringThe id of the session that ended.
durationSecondsRequired
numberTotal recorded duration, excluding paused time.
activityRequired
ActivityTypeThe session's primary activity.
averageQualityRequired
QualityLevelThe average tracking quality across the whole session.

Example

session-ended.tsTypeScript
tracker.on("sessionEnded", (summary) => {  saveSessionToServer(summary);});

Error events

Fired when the tracker encounters a runtime error outside a specific method call's promise.

errorTrackerErrorEventPayload

Fires 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

ParameterTypeDescription
messageRequired
stringA human-readable description of what went wrong.
codeRequired
stringA stable machine-readable error code, e.g. "camera_disconnected".
recoverableOptional
booleanWhether the tracker can recover on its own without calling init() again.

Example

error.tsTypeScript
tracker.on("error", ({ message, code, recoverable }) => {  console.error(`[${code}] ${message}`);  if (!recoverable) {    tracker.destroy();  }});