Track Mobile and Web Sessions

Mixpanel enables you to track sessions for mobile and web apps.

This article provides best practices on how to track mobile and web sessions.

Mobile Session Tracking

By default, Mixpanel tracks "App Session" ($ae_session) for mobile events.

The "App Session" event executes when the user spends more than ten seconds in the app.

This event also includes a property, “Session Length” ($ae_session_length) that reflects the number of seconds the user spent in the session.

To override the minimum or maximum session value, see Adjust Session Length Parameters for App Session Events for details.

To read more about "App Session" and other default mobile events that Mixpanel collects, see Default Mobile Events Collection.

Web Session Tracking

To track web sessions in Javascript, follow this general implementation process:

  1. Decide what triggers a session start.
  2. Decide what programmatically constitutes a session end.
  3. Calculate the elapsed time between start and end events.
  4. Append that elapsed time as an event property to either the session end event or the first event of the next session.

navigator.sendBeacon() 

The challenge with tracking session length in JavaScript is programmatically defining a "session-end" event. You can use navigator.sendBeacon() for exit tracking. It is also the safest, most sensible way to ensure any non-sent analytics do get sent out before leaving the page.

For an example, use:

window.addEventListener(" unload", ()=> navigator.sendBeacon(url, data));

mixpanel.time_event 

If you can programmatically define a "session-end" event in the context of your website (for example a "Page Close" event), you can return the time between the start and end event using mixpanel.time_event.

So you could call a "Page Open" event at the start of a session, and then call a "page_close" event when the session ends. Then use mixpanel.time_event to return the time between the start and end event.

When you call the "Page Close" event, an event property, “Duration” appends to the "Page Close" event with the elapsed time in seconds as the property value.

Is this article helpful?
24 out of 57 found this helpful

Comments

0 comments

Article is closed for comments.