how does mixpanel calculate the session end event
Mixpanel computes Session End events automatically (they are virtual events, not sent from your app) based on your project's session configuration. Here's how each mode works:
Timeout-Based Sessions (Default)
A session ends when a user stops performing events for longer than the configured timeout period (default: 30 minutes).
The timestamp of the Session End event is set to the time of the last event performed before the timeout elapsed โ not the time the timeout actually expired.
Sessions are also reset at midnight (project timezone), so the maximum session length is 24 hours. [Session Computation Deep-Dive]
Example: A user performs Event B at 1:10pm, then does nothing for 30 minutes. The Session End event is triggered, but its timestamp is 1:10pm (the last event), not 1:40pm. [Timeout Examples]
Event-Based Sessions
A session ends when the user performs the designated Session End event (e.g., "Logout").
If a Session End event occurs without a preceding Session Start event (e.g., across a midnight reset), no Session End event is created.
Sessions are also reset at midnight, so a Session Start and Session End that span midnight will not have a calculated duration. [Event-Based Sessions]
Property-Based Sessions
A session ends when the value of the designated session_id property changes on a new event, or when midnight resets the session.
Events without a session_id value are excluded from session calculations. [Property-Based Sessions]
Session End Properties
The Session End event carries these automatically computed properties:
Session Duration (Seconds): Time between Session Start and Session End.
Session Event Count: Number of events during the session (excluding hidden/excluded events).
Session End Event Name: The original event that triggered the Session End. [Session Properties]
Since sessions are computed dynamically at query time, you can change your session definition at any time and it will apply historically. [Sessions Overview]
โน๏ธย Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
There are a couple of plausible explanations based on what the knowledge sources cover:
Why Session Duration Shows 0 Seconds
If you're using Property-Based Sessions, a 0-minute (0-second) session duration is explicitly documented as possible. This happens when the session_id property value changes between two consecutive events โ the Session End timestamp is set to the time of the first event, and the Session Start of the new session is the second event, resulting in a duration of 0. [Property-Based Sessions]
If you're using Event-Based Sessions, a similar situation can occur if the Session Start and Session End events happen to be triggered at the same timestamp.
Why the Session Recording Shows Activity
Session replay works differently from session analytics โ it reconstructs the DOM changes (scrolling, clicks, etc.) that occurred during the user's time on the page. [How Session Replay Works] So it's possible the user was actively scrolling, but the session duration calculation in analytics came out as 0 due to how the session boundaries were defined (e.g., a session_id change between events, or a midnight reset causing a Session Start/End pair to lose their association).
What to Check
Which session type are you using? (Timeout-based, Event-based, or Property-based) โ check under Project Settings > Session Settings.
If Property-based: verify whether the session_id value changed between events for that user.
If Event-based: check whether the session spanned midnight, which would cause the duration to not be calculated. [Event-Based Sessions]
The knowledge sources don't provide more specific detail beyond these scenarios, so if none of these apply, I'd recommend reaching out to Mixpanel support for further investigation.
โน๏ธย Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
Given you're using Timeout-Based Sessions, here's why you might see a 0-second (or very short) session duration while the session replay shows activity:
The Core Issue
In timeout-based sessions, the Session End timestamp is set to the time of the last tracked event before the timeout expires โ not the time the user actually stopped interacting. [Session Computation Deep-Dive]
So if two events happen to be tracked at nearly the same timestamp (or the same second), the session duration will appear as 0 seconds, even if the user was visibly active in the recording between those events.
What to Check
Are relevant events being excluded from session calculations? If most of the user's interactions are tracked by events that are excluded from session settings (e.g., server-side or API events), Mixpanel may only "see" two events very close together, resulting in a near-zero duration. [Excluded Events]
Did the session span midnight? Sessions are reset at midnight (project timezone). If the session crossed midnight, the Session End timestamp is set to the last event before midnight, and a new session starts after. This can produce unexpectedly short durations. [Session Computation Deep-Dive]
Are enough user-action events being tracked? Session duration is only as accurate as the events you send. If you're not tracking granular user interactions (e.g., page views, clicks), Mixpanel has fewer data points to calculate an accurate session length.
The session replay captures DOM activity independently of your event tracking, which is why it can show scrolling even when the analytics session duration appears to be 0.
โน๏ธย Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
