Skip to content

Reference

Exported functions

deviceIdentifier()

Returns the native TrainingKit device identifier as a string.

ts
function deviceIdentifier(): string

This call is synchronous on both iOS and Android. The identifier is stable for a given device installation.

Use it as the value of the X-TrainingKit-Device HTTP header on every GraphQL request.


launchWorkout(session)

Launches the native workout experience from a TrainingKit session payload.

ts
function launchWorkout(session: TrainingKitSession): void

The function inspects session.__typename and session.format to determine which native flow to launch:

ConditionNative flow
__typename === 'WorkoutBlockSession' or format === 'CLASSIC'Classic workout
__typename === 'WorkoutVideoSession' or format === 'PLAY'Video workout

Throws if trainingKitToken is missing or if the session type cannot be identified.


addWorkoutListener(listeners)

Subscribes to the workout lifecycle emitted by the native SDKs.

ts
function addWorkoutListener(listeners: WorkoutListeners): EmitterSubscription

Add the listener before calling launchWorkout(session) so save, quit, and tracking events cannot be missed. Call .remove() on the returned subscription when the host screen unmounts or no longer needs workout events.

ts
const subscription = addWorkoutListener({
  onSave: (workout) => {
    // Persist completed workout state.
  },
  onQuit: () => {
    // The user exited before completing the workout.
  },
  onEvent: (name, properties) => {
    // Forward analytics metadata if needed.
  },
})

subscription.remove()
CallbackTriggerPayload
onSave(data)The workout completed and produced session state.WorkoutSaveData, mirroring native SaveWorkoutState (richer on iOS than Android).
onQuit()The user quit without completing the workout.None.
onEvent(name, properties)TrainingKit emitted a tracking event.Event name and property object.

Types

TrainingKitSession

ts
type TrainingKitSession = {
  __typename?: string
  format?: string
  trainingKitToken: string
  [key: string]: unknown
}

The minimum shape required by launchWorkout. The full GraphQL session payload (which may contain many additional fields) satisfies this type and is passed through to the native SDK as a JSON string.

WorkoutListeners

ts
type WorkoutListeners = {
  onSave?: (data: WorkoutSaveData) => void
  onQuit?: () => void
  onEvent?: (name: string, properties: Record<string, unknown>) => void
}

type WorkoutSaveData = Record<string, unknown>

The listener callbacks used by addWorkoutListener.

Native module

The package registers a single native module named TrainingKitModule. It is loaded automatically on both platforms via React Native autolinking.

The underlying native methods are not intended to be called directly:

MethodDescription
deviceIdentifier()Returns the native device ID
launchClassicWorkout(jsonString, token)Launches the classic workout controller
launchVideoWorkout(jsonString, token)Launches the video workout controller
addListener(eventName) / removeListeners(count)React Native event emitter plumbing for workout lifecycle events

Use deviceIdentifier(), launchWorkout(), and addWorkoutListener() from the package instead.

Error messages

MessageCause
TrainingKitModule is not available. Make sure trainingkit-reactnative is linked and the native app was rebuilt.The native module was not found. The app needs a native rebuild after installing the package.
TrainingKit session is missing trainingKitToken.The session object passed to launchWorkout does not contain trainingKitToken. Check that the full session payload was fetched before calling launchWorkout.
Unsupported TrainingKit session type: <type>.The __typename and format fields do not match any known workout kind. Verify the GraphQL response.