Manual Session Tracking in RudderStack SDKs

Learn about the manual session tracking feature in RudderStack SDKs.

This guide explains the manual session tracking feature available in the supported RudderStack SDKs (JavaScript, Android, iOS, React Native, and Flutter).

Overview

You can use the manual session tracking feature to define the start and end of a user session.

warning
Manual session tracking overrides the automatic session tracking.

RudderStack supports the following manual session tracking methods:

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

RudderStack does not recommend using a decimal number as the sessionId.
endSession()-RudderStack clears the sessionId and ends the session.

Persistence scope

The following sections list the persistence scope of manual session tracking in the JavaScript and mobile SDKs.

JavaScript

The persistence scope of manual session tracking in the JavaScript SDK does not depend on whether automatic session tracking is enabled.

If you call startSession(), the manual session continues even if you refresh or reopen the web page. To end the session, you must call endSession().

warning
If you identify a user with a new userId in an existing session, RudderStack triggers a reset() call. This ends the existing session and generates a new one, irrespective of whether endSession() is called or not.

Mobile SDKs

The persistence scope of manual session tracking in the mobile SDKs (Android, iOS, React Native, and Flutter) depends on whether automatic session tracking is enabled:

  • If automatic session tracking is enabled and you call startSession(), then RudderStack disables automatic session tracking until the app is closed completely. Once you restart the app, the SDKs resume automatic session tracking.
  • If automatic session tracking is disabled and you call startSession(), the manual session is active until you end it by calling endSession().

Sample snippets

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

FAQ

See the Session Tracking FAQ guide for answers to some commonly-asked questions on session tracking.



Questions? Contact us by email or on Slack