Automatic Session Tracking in Mobile SDKs

Learn about the automatic session tracking feature in the mobile SDKs.

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

Overview

The mobile SDKs support automatic session tracking with the following capabilities:

  • All mobile SDKs (Android, iOS, React Native, and Flutter) enable automatic session tracking by default. They consider the Application Opened, Application Installed, or Application Updated events as the start of a new session.

  • By default, each session remains active for 5 minutes of inactivity (30 minutes for Flutter web platforms). You can customize this timeout period for each SDK.

  • The SDKs generate a unique sessionId for each session. They also provide a method to retrieve the current session ID.

  • The SDKs automatically reset sessions in the following scenarios:

    • After the specified inactivity period
    • When you call the reset() API
    • When you identify a user with a new userId
warning

To automatically track user sessions:

  • withTrackLifecycleEvents should also be set to true in the Android and iOS SDKs.
  • trackAppLifecycleEvents should be set to true in the React Native SDK.

See the Session tracking flow section for a visual workflow of automatic session tracking in the mobile SDKs.

Manage automatic session tracking

By default, the supported mobile SDKs automatically track user sessions. This section explains how to manage automatic session tracking in the different SDKs.

Retrieve the session ID

This section explains how to retrieve the current session ID in the different mobile SDKs.

Session expiration in mobile SDKs

By default, a session is active until 5 minutes of inactivity have elapsed. For Flutter SDK, this limit is 5 minutes for mobile platforms and 30 minutes for web platforms. However, you can adjust this limit using the following load option in the respective SDKs:

Load optionRudderStack SDKDefault value
sessionTimeoutMillisAndroid and iOS5 minutes
sessionTimeoutiOS v2 and React Native5 minutes
sessionTimeoutInMillisFlutter
  • 5 minutes (mobile platforms)
  • 30 minutes (web platforms)

If the duration between the last received event and the next Application Opened event is more than the session timeout, RudderStack automatically starts a new session. Otherwise, it continues the previous session.

Calling the reset method clears the current sessionId and generates a new one.

Session tracking flow

The automatic session tracking flow (when enabled) in the mobile SDKs is as follows:

  1. RudderStack starts the session once it receives the Application Opened, Application Installed, or Application Updated event.
  2. The SDK then generates a sessionId.
info
See the Session Tracking FAQ guide for more information on how RudderStack calculates sessionId.
  1. The SDK records the user events and the session is active until more than sessionTimeoutMillis (default 5 minutes) period of inactivity has elapsed since the last received event. See Session expiration in mobile SDKs for more information.
Session tracking in mobile SDKs

FAQ

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



Questions? Contact us by email or on Slack