Session Tracking in RudderStack SDKs
3 minute read
This guide explains the session tracking feature in RudderStack.
Overview
RudderStack provides a session tracking feature that helps you track user sessions and gather event tracking metrics. You can use this feature to:
- Combine events with session metadata to better understand the user’s product journey and analyze their behavior.
- Use the insights to identify problems and optimization opportunities in your product workflow.
What is a session?
A session is a group of user interactions with your website or mobile app within a given time frame. It is usually triggered when a user opens a mobile app or a website in their browser and ends after a particular period of inactivity.
A single session can contain multiple page views or screen views, events, social interactions, and ecommerce transactions.
Session tracking in RudderStack SDKs
The following RudderStack SDKs support the session tracking feature:
| RudderStack SDK | Minimum supported version |
|---|---|
| JavaScript |
|
| Android (Java) | v1.7.0 |
| iOS (Obj-C) | |
| React Native | v1.8.0 |
| Flutter | v2.7.0 |
You can expect the following properties in your event’s context object object when session tracking is enabled:
| Property | Type | Description |
|---|---|---|
sessionId | Number | The session ID. See the FAQ guide for more information on how RudderStack calculates sessionId . |
sessionStart | Boolean | Present in the first event, indicating the start of the session. |
Note the following:
- RudderStack’s automatic session tracking feature overrides any
sessionIdpresent in the event’scontextobject.- Make sure to send any other session-related information within the event’s
traitsorpropertiesobject.
Session tracking types
The RudderStack SDKs mentioned above support two types of session tracking:
| Type | Description |
|---|---|
| Automatic session tracking | RudderStack automatically determines the start and end of a session based on the inactivity time configured in the SDK. |
| Manual session tracking | You can manually start and end a session using the SDK methods. |
For the JavaScript SDK session APIs (startSession, endSession, and getSessionId), see Session tracking.
Supported downstream tools
The RudderStack SDKs support sending the sessionId and sessionStart fields to all cloud and warehouse destinations, within the event’s context.
It is important to note the following:
- RudderStack passes the
sessionIdto the subsequent events in thecontext.sessionIdfield. - RudderStack sets the
context.sessionStartfield totruein the first event to indicate the start of the session.
RudderStack maps sessionId to specific fields only in case of the following two destinations:
| Destination | Notes |
|---|---|
| Amplitude | RudderStack maps sessionId to Amplitue’s session_id field. For more information, see the Amplitude documentation. |
| Mixpanel | $session_id under the event properties.$session_id but you can use this field in the reports. |
FAQ
See the Session Tracking FAQ guide for answers to some commonly-asked questions on session tracking.