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.
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 or disabled.
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().
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.
Android/iOS/React Native/Flutter
The persistence scope of manual session tracking in the mobile SDKs depends on the status of automatic session tracking:
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:
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
// Starts a new user session and automatically assigns a session ID.
rudderClient.startSession()// Passes a custom session ID while creating a new session.
rudderClient.startSession(sessionId)// Ends the user session and clears the session ID.
rudderClient.endSession()
rudderClient.startSession();// Starts a new user session and automatically assigns a session ID.
rudderClient.startSession(sessionId);// Passes a custom session ID while creating a new session.
rudderClient.endSession();// Ends the user session and clears the session ID.
iOS
RSClient.sharedInstance()?.startSession()// Starts a new user session and automatically assigns a session ID.RSClient.sharedInstance()?.startSession(sessionId)// Passes a custom session ID while creating a new session.RSClient.sharedInstance()?.endSession()// Ends the user session and clears the session ID.
[[RSClientsharedInstance]startSession];// Starts a new user session and automatically assigns a session ID.
[[RSClientsharedInstance]startSession:sessionId];// Passes a custom session ID while creating a new session.
[[RSClientsharedInstance]endSession];// Ends the user session and clears the session ID.
React Native
// Starts a new user session and automatically assigns a session ID.
rudderClient.startSession();// Passes a custom session ID while creating a new session.
rudderClient.startSession(sessionId);// Ends the user session and clears the session ID.
rudderClient.endSession();
Flutter
// Starts a new user session and automatically assigns a session ID.
rudderClient.startSession();// Passes a custom session ID while creating a new session.
rudderClient.startSession(sessionId);// Ends the user session and clears the session ID.
rudderClient.endSession();
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.