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
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.
The following snippet highlights the use of the withAutoSessionTracking load option to enable automatic session tracking in the Android SDK:
valrudderClient=RudderClient.getInstance(this,WRITE_KEY,RudderConfig.Builder().withDataPlaneUrl(DATA_PLANE_URL).withAutoSessionTracking(true)// Set to false to disable automatic session tracking
.withSessionTimeoutMillis(5*60*1000).build())
The corresponding Java code is as follows:
RudderClientrudderClient=RudderClient.getInstance(this,WRITE_KEY,newRudderConfig.Builder().withDataPlaneUrl(DATA_PLANE_URL).withAutoSessionTracking(true)// Set to false to disable automatic session tracking
.withSessionTimeoutMillis(5*60*1000).build());
You can disable automatic session tracking by setting withAutoSessionTracking to false.
The following snippet highlights the use of the withAutoSessionTracking load option to enable automatic session tracking in the iOS SDK v1:
RSConfigBuilder*builder=[[RSConfigBuilderalloc]init];[builderwithDataPlaneUrl:DATA_PLANE_URL];[builderwithAutoSessionTracking:YES];// Set to NO to disable automatic session tracking
[builderwithSessionTimeoutMillis:(5*60*1000)];[RSClientgetInstance:WRITE_KEYconfig:[builderbuild]];
The corresponding Swift code is as follows:
letbuilder:RSConfigBuilder=RSConfigBuilder().withDataPlaneUrl(DATA_PLANE_URL).withAutoSessionTracking(true)// Set to false to disable automatic session tracking.withSessionTimeoutMillis(5*60*1000)RSClient.getInstance(WRITE_KEY,config:builder.build())
You can disable automatic session tracking by setting withAutoSessionTracking to false.
The following snippet highlights the use of the autoSessionTracking load option to enable automatic session tracking in the iOS SDK v2:
You can disable automatic session tracking by setting autoSessionTracking to false.
The following snippet highlights the use of the autoSessionTracking load option to enable automatic session tracking in the React Native SDK:
construdderInitialise=async()=>{awaitrudderClient.setup(WRITE_KEY,{dataPlaneUrl: DATA_PLANE_URL,trackAppLifecycleEvents: true,autoSessionTracking: true,// Set to false to disable automatic session tracking
sessionTimeout: 5*60*1000,});};rudderInitialise().catch(console.error);
You can disable automatic session tracking by setting autoSessionTracking to false.
The following snippet highlights the use of the autoSessionTracking load option to enable automatic session for web platforms:
finalRudderControllerrudderClient=RudderController.instance;WebConfigwc=WebConfig(autoSessionTracking:true,sessionTimeoutInMillis:10*60*1000);// setting the session timeout to 10 mins
RudderConfigBuilderbuilder=RudderConfigBuilder();builder..withDataPlaneUrl("DATA_PLANE_URL")..withWebConfig(wc);rudderClient.initialize("WRITE_KEY",config:builder.build());
The following snippet highlights the use of the autoSessionTracking load option to enable automatic session for mobile platforms:
finalRudderControllerrudderClient=RudderController.instance;MobileConfigmc=MobileConfig(autoSessionTracking:true,sessionTimeoutInMillis:3*60*1000);// setting the session time out to 3 mins
RudderConfigBuilderbuilder=RudderConfigBuilder();builder..withDataPlaneUrl("DATA_PLANE_URL")..withMobileConfig(mc)rudderClient.initialize("WRITE_KEY",config:builder.build());
You can disable automatic session tracking by setting autoSessionTracking to false.
Retrieve the session ID
This section explains how to retrieve the current session ID in the different mobile SDKs.
The Android SDK provides a getSessionId method to fetch the current session’s sessionId. In case the session ID is unavailable, this method returns a null value.
The getsessionId() method is available in the Android SDK from v1.19.0 onwards.
The following snippet highlights the use of the getSessionId method:
RudderClient.getInstance()?.sessionId
The iOS SDK v1 provides an instance variable sessionId to fetch the current session ID. In case the session ID is unavailable, it returns a null value.
The sessionId instance variable is available in the iOS SDK v1 from v1.20.0 onwards.
The following snippet highlights the use of the sessionId instance variable:
[RSClientsharedInstance].sessionId// OR
[[RSClientsharedInstance]sessionId]
The corresponding Swift code is as follows:
RSClient.sharedInstance()?.sessionId
Unlike iOS SDK v1, the iOS SDK v2 does not support fetching the current session ID as of now. This feature is coming soon.
The React Native SDK provides a getSessionId method to fetch the current session’s ID. If the session ID is unavailable, this method returns a null value.
The following snippet highlights the use of the getSessionId method:
constsessionId=awaitrudderClient.getSessionId();
The Flutter SDK provides a getSessionId method to fetch the current session’s sessionId. In case the session ID is unavailable, this method returns a null value.
The following snippet highlights the use of the getSessionId method:
int?sessionId=awaitrudderClient.getSessionId();
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 option
RudderStack SDK
Default value
sessionTimeoutMillis
Android and iOS
5 minutes
sessionTimeout
iOS v2 and React Native
5 minutes
sessionTimeoutInMillis
Flutter
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:
See the Session Tracking FAQ guide for more information on how RudderStack calculates sessionId.
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.
FAQ
See the Session Tracking FAQ guide for answers to some commonly-asked questions on session tracking in the mobile SDKs.
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.