Track sessions
Sessions help you measure how often and how long users engage with your product. Use the User Sessions chart to build a session-based analysis.
How Amplitude defines sessions
A session is the period when a user has your app in the foreground or has your website open. Session behavior differs between mobile and browser applications:
- For mobile, a session begins when the app moves into the foreground. A mobile session ends when the app goes into the background and sends no events for at least five minutes. Events sent within five minutes of each other count toward the current session. You can define a custom session expiration time with
setMinTimeBetweenSessionsMillis(timeout), wheretimeoutis in milliseconds. - On a browser, a session begins when the website loads and the SDK initializes. A browser session ends when the last event occurs. Web sessions time out after 30 minutes by default. Events sent within 30 minutes of each other count toward the same session. You can customize the browser timeout window with the Browser SDK configuration options.
Amplitude automatically generates a session ID for each new session. The session 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. Amplitude SDKs manage session IDs automatically. If you send data to Amplitude through the HTTP API, explicitly set the session ID field to track sessions.
How Amplitude counts sessions
To count sessions, Amplitude filters for events marked as "active," applies the project's session definition, groups the filtered events into sessions, and counts the grouped sessions.
For more information about setting a project's session definition, review Manage Organizations and Projects.
How Amplitude groups events into sessions
By default, Amplitude uses session ID as the session property. Amplitude groups all events with the same session ID and the same user ID into the same session. The session ID doesn't need to be unique across multiple users. You can change the property you use to group sessions.
Amplitude SDKs automatically generate and manage session IDs for events. For events sent through the HTTP API, Amplitude defaults to a session ID of -1. A session ID of -1 excludes the event from all session metrics.
A session ID of -1 commonly occurs when data comes to Amplitude from Segment through a cloud-mode connection. As with data sent through the HTTP API, you need to explicitly set a session ID to track sessions.
In a user's event stream, a blue line connects events in the same session.
Amplitude assigns a session to a specific date based on its actual start time. The start time must fall within a chart's selected date range for Amplitude to include the session on that chart.
For example, a session begins on May 17 at 8:00 PM and ends on May 18 at 1:30 AM. The session appears on charts where the selected date range includes May 17, the date when the session began. The date range for the example session can start on or before May 17 and end on or after May 17. If the chart's date range starts on May 18, the session doesn't appear on the chart, even though the session was still active on May 18.
Start Session and End Session events
By default, Amplitude derives Start Session and End Session events from each session's session ID. Amplitude also uses session ID to calculate session lengths. If you use session IDs, Amplitude doesn't add extra events to your monthly event volume limit.
If you need Start Session and End Session events for analysis beyond session lengths, enable Start Session and End Session event tracking by adding the following code before initializing the SDK:
For Android:
Amplitude amplitude = new Amplitude(new Configuration(apiKey = AMPLITUDE_API_KEY, context = applicationContext, trackingSessionEvents = true, ));
For iOS:
[Amplitude instance].trackingSessionEvents = YES;
For Browser:
amplitude.init(API_KEY, OPTIONAL_USER_ID, {
defaultTracking: {
sessions: true,
},
});
Start Session and End Session limitations
- Session event tracking applies only to Amplitude's Android, iOS, and Browser SDKs.
Start SessionandEnd Sessionevents count toward your monthly event volume limit.- Amplitude sends the
End Sessionevent at the start of the user's next session. - By default, you can't add extra event properties to automatically generated
Start SessionandEnd Sessionevents. To send event properties for session start and end events, you have two options:- Implement your own custom
Open AppandClose Appevents. - Use an Enrichment Plugin to add properties to the generated session events. Enrichment plugins let you modify properties in Event objects.
- Implement your own custom
Out-of-session events
You can log events outside a session by setting the session ID to -1. Out-of-session events aren't part of the current session and don't extend the current session. Out-of-session events are useful for events triggered by push notifications.
Out-of-session events are usually server-side events received by Amplitude. For more information, refer to the HTTP API documentation. Out-of-session events appear in a user's event stream as disconnected green squares.
Configure a custom session definition
By default, Amplitude sorts events into sessions by session ID. You can define sessions without adding instrumentation. A custom session definition can use a constant property, a custom timeout window, or beginning and ending events.
You need Admin or Manager privileges to edit session definitions.
Custom session definitions are only available in the User Sessions and Pathfinder charts and user timelines. Sessions only include active events.
To configure a custom session definition:
From the left sidebar, navigate to Settings > Projects.
Select the project you want to work with.
Select Session Definitions. The Session Definitions modal appears.
Select Custom Session Definition.
Configure one or more conditions:
- Session property: Select Select property... and choose the event or user property for grouping sessions.
- Starting Event and Ending Event: Select Starting Event or Ending Event and choose the events that mark the beginning and end of a session. The ending event ends a session if the ending event occurs before the timeout interval elapses.
- Session timeout: Enter the default timeout interval in minutes. Amplitude counts events from the same user that occur within the specified timeout interval as part of one session. Amplitude recommends a default of 30 minutes.
Enter the confirmation phrase and select Save.
Changing the session definition applies to all User Sessions, Funnel Analysis, and Journeys charts, and to the session metric in your project. Review the impact before you configure or change a custom session definition.
Amplitude combines conditions with and logic. A session must meet all configured conditions to count. If you don't configure any conditions, Amplitude uses session ID as the session-defining property.
To require all events in a session to come from the same source, use session property and timeout window together:
- Session property =
device ID - Session timeout =
30 min
To define sessions based on in-app usage, use starting event and timeout window:
- Start event =
app open - Session timeout =
5 min
Was this helpful?