Manual Session Tracking

Manually tracking user sessions using the RudderStack SDKs.

RudderStack supports manual session tracking that lets you define the start and end of a user session.

The RudderStack SDKs (JavaScript, Android, and iOS) support the following manual session tracking methods:

MethodParametersDescription
startSession()-If you don't pass any parameter, RudderStack creates a new session and passes the current timestamp as the sessionId.
sessionId
Long integer with minimum length of 10 characters.
If you pass a custom sessionId parameter, RudderStack triggers a new user session.

It is not recommended to use a decimal number as the sessionId.
endSession()-RudderStack clears the sessionId and ends the session.
warning
Manual session tracking overrides automatic session tracking.

Note that if automatic session tracking is enabled and you call the startSession() method, then RudderStack disables automatic session tracking until the app is closed completely. Upon restarting the app, the RudderStack SDKs resume automatic session tracking.

For more information on the persistence scope of manual session tracking, refer to the FAQ guide.

Sample snippets

The following snippets highlight the use of the manual session tracking methods:

JavaScript

rudderanalytics.startSession() // Starts a new user session and automatically assigns a session ID.

rudderanalytics.startSession(sessionId) // Passes a custom session ID while creating a new session.

rudderanalytics.endSession() // Ends the user session and clears the session ID.

Android

iOS


Questions? Contact us by email or on Slack