JavaScript SDK ⁠-⁠ 'startOfflineRecording' method

Starts session recording in offline mode (nothing being sent unless triggered to upload) returns methods to control the recording state.

Note: The session and events timestamps will be extracted from the user’s device, and not synchronised with our backend.

startOfflineRecording(
  startOpts?: Partial<StartOptions>, 
  onSessionSent: () => void
): { saveBuffer, getBuffer, setBuffer }

With the startOpts you can customize different aspects of the recording:

  • userID: string: Used to manually set the userID to track it across sessions. This is a string value and it can be anything you want.
  • metadata: Record<string, string>: Manually set the metadata values. Check the Metadata section to learn more about this feature.
  • forceNew: boolean: Used to force a new session after page refresh. By default it’s set to false, so after a refresh the session is kept.
  • sessionHash: string: Used for sticky sessions. Useful if you have a multi-site application or if you have to redirect the user outside and then back into your site (like to a payment gateway).
  • onSessionSent: Callback that will be called once session is fully uploaded.
  • saveBuffer(): void - Saves the current buffer to the localStorage object (customizable in constructor), buffer will be autoloaded once startOfflineRecording is called.
  • getBuffer(): Messages[] - Returns the current messages buffer.
  • setBuffer(buffer: Messages[]) - Replaces the current buffer with the given one (if you’re using alternative temporary saving methods).