JavaScript SDK - 'start' method
This method is used to start the tracker. By starting the tracker, the recording of the session starts.
Signature
Section titled Signaturestart(startOpts?: Partial<StartOptions>): Promise<StartPromiseReturn>
Parameters
Section titled ParametersThe start
method accepts an optional parameter where you can customize different aspects of the recording:
userID: string
: used to manually set the user ID to track it across sessions. This is a string value and it can be anything you want.metadata: Record<string, string>
: manually set 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 tofalse
, 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).assistOnly: boolean
: launches tracker in assist-only mode which will skip sending session data to backend (EE edition feature)startCallback?: (result: StartPromiseReturn) => void
: A callback triggered when the tracker starts or fails to start. Returns either success or failure information.
Return value
Section titled Return valueOnce started, the method will return a promise with a session info object containing:
sessionID: string
: A string value representing the ID of the started session.sessionHash: string
: The hash of the session.userUUID: string
: A unique identifier for the user.
The StartPromiseReturn
can be either:
// Successful start
interface OnStartInfo {
sessionID: string;
sessionToken: string;
userUUID: string;
}
const SuccessfulStart = (body: OnStartInfo): SuccessfulStart => ({
...body,
success: true,
});
// Unsuccessful start
const UnsuccessfulStart = (reason: string): UnsuccessfulStart => ({
reason,
success: false,
});
// Type for start promise return
export type StartPromiseReturn = SuccessfulStart | UnsuccessfulStart;
- Success case: If successful, the promise will return sessionID, sessionToken, and userUUID.
- Failure case: If unsuccessful, it will return reason and success: false.