Client
activity.current
The currently active activity instance, or null if none is running.
activity.start(params)
Creates and starts a new activity tracker. Heartbeats begin immediately unless time: false is passed.
Activity slug: a stable, URL-safe identifier for the learning object (e.g.
"fractions-with-like-denominators"). Used to construct the canonical activity URL in Caliper
events.Human-readable display name (e.g.
"Fractions with Like Denominators"). Sent as
object.activity.name in Caliper events.Course selector: must match a course in
timeback.config.json. Either { subject, grade } or { code }.Unique identifier for correlating events across sessions. If omitted, the SDK generates a new
UUID. Pass the same
runId when resuming a stateful
activity to link heartbeats with the
eventual completion event.Time tracking configuration. All fields are optional: defaults work well for most apps.
Called when a time-spent flush or completion submission fails. When
retryAttempts is configured, only fires after all retries are exhausted. Time-spent errors are non-fatal: the SDK continues tracking. Completion errors (from end()) are also surfaced here before being re-thrown.Called when the activity is paused, either explicitly via
pause() or automatically when the
hidden timeout
fires.Called when the activity resumes, either via
resume() or when the user returns after a hidden
timeout.Called after each successful heartbeat flush with the active milliseconds reported in that
window.
Examples
Activity instance
The object returned byactivity.start().
Properties
The activity slug passed to
start().When the activity was started.
Whether the activity is currently paused.
Whether
end() has completed successfully.Once true, the activity is no longer active and a new one can be started.Unique identifier correlating heartbeats and completion events for this run.
Cumulative active time across all flushed heartbeat windows plus the current in-progress window.
Active time for the current heartbeat window only. Resets to 0 after each flush.
Methods
pause()
Flushes accumulated time, then stops heartbeats until
resume() is called. Fires onPause if
provided.resume()
Starts a fresh tracking window and restarts heartbeats. Fires
onResume if provided.Manually flush accumulated time to the server. No-op when time tracking is disabled or the
activity is paused. Serialized — only one flush can be in flight at a time.
activity.end(data?)
Ends the activity. Always flushes remaining time data. If completion data is provided, also sends an ActivityCompletedEvent.
If the network call fails, the activity remains usable so the caller can retry.
onError fires with { type: 'completion' } before the error is re-thrown.Completion data
XP earned for this activity. Must follow the 1 XP = 1 focused
minute rule.
Total questions in the activity. Must be paired with
correctQuestions.Questions answered correctly. Must be paired with
totalQuestions.Number of new units (lessons) the student mastered during this activity. This is an
incremental count, not a cumulative total. The server sums these across submissions and divides
by
totalLessons to
auto-compute pctComplete when it is omitted. See Course
progress for details.Course completion percentage (0—100). If omitted and
masteredUnits is provided, the server
auto-computes this from
gradebook history. If provided, the server forwards it as-is.Override the SDK’s automatic time tracking with explicit values. Use this for advanced scenarios
like offline sync or batch imports where the SDK wasn’t tracking time in real-time.
totalQuestions and correctQuestions must be provided together.If you provide one, you must provide the other.Server
timeback.activity.record(params)
Records an activity completion from the backend. Sends an ActivityCompletedEvent to the Caliper API and runs the full pipeline including gradebook and XP.
See the server adapter docs for setup.
Student identity. Provide
email (required) and optionally timebackId. See
Identity for how users are resolved.Activity identity.
Completion metrics.
Optional time data. Include when the backend tracks accumulated session time — for example, when
the frontend uses
time: false, or for
offline sync and batch imports.UUID correlating this completion with frontend heartbeats. Should match the
runId persisted
when the activity was started on the client.totalQuestions and correctQuestions must be provided together.If you provide one, you must provide the other.Examples
With time data
Only includetime when the frontend uses time: false, meaning your server owns time tracking. Do not pass time here if the frontend is sending heartbeats (the default), or time will be double-counted.