RudderStack supports manual session tracking that lets you define the start and end of a user session.
Manual session tracking methods
The RudderStack SDKs (JavaScript, Android, and iOS) support the following manual session tracking methods:
Method | Parameters | Description |
---|---|---|
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. |
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
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.
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.
[[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.
Contact us
For more information on the topics covered on this page, email us or start a conversation in our Slack community.