Sessions
How a session is defined, the session properties you can analyse, and how to join server-side events or your own session IDs to a session.
A session is one visit: the run of events a visitor produces from arriving until they go quiet. Sessions power visit counts, bounce rate and session duration in web analytics, group events into session replays, and let you analyse properties of the visit as a whole, such as where it came from.
How a session starts and ends
The web library gives every event a $session_id. A new session starts when:
- a visitor arrives for the first time;
- they come back after 30 minutes or more without activity;
- the current session has lasted 24 hours.
The idle time can be changed with the library's session_idle_timeout_seconds option, anywhere from 60 seconds to 10 hours; see Configuring the library.
Each session belongs to one person. myjourney.reset() also starts a new session.
Session properties
Besides the properties on each event, every session has properties that describe the visit as a whole, worked out from its events. For example:
| Property | What it holds |
|---|---|
| Entry and exit pages | The first and last page of the visit. |
| Session duration | Time from the first event to the last. |
| Pageview count | How many pages were viewed. |
| Bounce | Whether the visitor left without engaging. |
| Entry referring domain and UTM parameters | Where the visit came from. |
| Channel type | The marketing channel, worked out from the above. See Channel type. |
You can filter and break down insights by session properties, and browse sessions under Activity → Sessions.
Server SDKs and sessions
Events you send from your server have no session unless you give them one. To join a server event to the visitor's current session, read the session ID in the browser and send it to your server:
const sessionId = myjourney.get_session_id();
// send sessionId to your server with the requestThen include it as the $session_id property of the server event. Send the visitor's distinct ID too, from myjourney.get_distinct_id(), so the event lands on the same person.
Server events without a $session_id still count in your insights, but they are not part of any session, recording or session property.
Custom session IDs
If you send events from somewhere the web library does not run, you can set $session_id yourself to group them into sessions.
- Use a UUID version 7 for each session. The session's start time is read from the ID, so other kinds of ID do not work as session IDs.
- Create a new ID for each visit, and reuse it for every event in that visit.
- Keep a session to one person.
Related
Can't find what you need? Contact support