This article helps you:
Understand how Amplitude defines and tracks user sessions
Learn how to best incorporate sessions into your analyses
In Amplitude, sessions are a useful metric for understanding the frequency and duration of your users' engagement with your product. The most direct way to build a session-based analysis is with the User Sessions chart.
You may also find this video on User Sessions helpful.
Generally, a session is the period of time a user has your app in the foreground or has your website open. The specifics differ slightly between mobile and web applications:
setMinTimeBetweenSessionsMillis(timeout)
, where the timeout input is in milliseconds.Amplitude automatically generates a session ID for each new session; that ID is the session's start time in milliseconds since epoch (also known as the Unix timestamp). All events within the same session share the same session ID. If you are using Amplitude's SDKs, this happens automatically. However, if you are sending data to Amplitude using the HTTP API, you will have to explicitly set the session ID field in order to track sessions.
By default, the setting in Amplitude for the session property is session ID. All events with the same session ID and the same user ID will be grouped into the same session. The session ID does not have to be unique across multiple users. You can also change the property you use to group sessions.
As noted above, session IDs for events sent via the Amplitude SDKs are automatically generated and managed. However, for events sent via the HTTP API, Amplitude defaults to a session ID of -1
. This means the event is excluded from all session metrics.
This commonly occurs when sending data to Amplitude from Segment via a cloud-mode connection. As with sending data via HTTP API, you will have to explicitly set a session ID to track sessions.
Events included in the same session will be connected with a blue line, as shown above.
By default, Amplitude tracks Start Session
and End Session
events using the beginning and ending times of each session by session ID. Amplitude also uses session ID to calculate session lengths. If you use session IDs, Amplitude will not add additional events to your monthly event volume limit.
That said, if trackingStart Session
andEnd Session
events is critical to your analysis outside of session lengths, you can easily turn on tracking for these events by adding this line of code before initializing the SDK:
For Android:
1Amplitude amplitude = new Amplitude(new Configuration( apiKey = AMPLITUDE\_API\_KEY, context = applicationContext, trackingSessionEvents = true, ));
For iOS:
1[Amplitude instance].trackingSessionEvents = YES;
For Browser:
1amplitude.init(API\_KEY, OPTIONAL\_USER\_ID, { defaultTracking: { sessions: true, }, });
Important Notes:
End Session
event will be sent at the start of the user's next session.Open App
and Close App
events.You can also log events as out-of-session by setting the session ID to -1
. Out-of-session events are not considered part of the current session. Because they do not extend the current session, they can be useful if you're logging events triggered by push notifications.
Out-of-session events are normally server-side events received by Amplitude (see our HTTP API documentation for more details). These events will appear in a user's event stream as disconnected green squares.
By default, Amplitude sorts events into sessions according to session ID. You can also define a session without instrumentation, simply by setting a constant property, custom timeout window, or beginning and ending events to group sessions.
You will need Admin or Manager privileges to edit session definitions.
Custom session definitions are only available in the User Sessions and Pathfinder charts, as well as user timelines. Sessions only include active events.
To set a custom session definition, follow these steps:
You can define one condition or multiple conditions, but be aware that all conditions you specify must be met in order for Amplitude to count a session. If you do not define any of these conditions, Amplitude will use session ID as the session-defining property.
Changing the session definition will apply to all User Session, Funnel Analysis, Journeys charts, as well as the session metric, in your project. Be sure you understand what the impacts might be before setting or changing a custom session definition.
Be aware that Amplitude will treat combinations of conditions as and logic, meaning all conditions must be met for the session to be counted. For example, if you want to guarantee that all events in sessions are from the same source, you can accomplish this by using session property and timeout window in tandem:
device ID
30 min
Alternatively, to define sessions based on in-app usage, you can use starting event and timeout window:
app open
5 min
Thanks for your feedback!
June 11th, 2024
Need help? Contact Support
Visit Amplitude.com
Have a look at the Amplitude Blog
Learn more at Amplitude Academy
© 2024 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.