The power of Mixpanel is that it's completely customizable, and the data is driven by Events that are important to your particular business (as opposed to more generic one-size-fits-all metrics, like pageviews or, in many ways, session time).
Mixpanel tracks App Session ($ae_session) for mobile events by default. The App Session event is fired if the user spends more than 10 seconds in the app. This event also includes a property, “Session Length,” that reflects the number of seconds the user spent in the session. If you’d like to override the minimum and/or maximum session value you can do so following the details here.
To read more about App Session and other default mobile events collected by Mixpanel, click here.
- Decide what triggers a session start.
- Decide what programmatically constitutes a session end.
- Calculate the elapsed time between start and end Events.
- Append that elapsed time as an Event Property to either the session end Event or the first Event of the next session.
navigator.sendBeacon() supports this kind of use case. This could be used for exit tracking, and is also the safest, most sensible way to insure any non-sent analytics do get sent out before leaving the page.
An example use:
If you can programmatically define a session-end event in the context of your website (for example a Log Out Event), you can return the time between the start and end Event using mixpanel.time_event.
Call time_event at the session-start Event with the session-end Event name in the argument. When the track call is made for the session-end Event, an Event Property called “Duration” will be appended to the session-end Event with the elapsed time in seconds as the Property value.