How the Leanplum SDK tracks sessions
Once you complete our initial SDK setup, Leanplum will track your users' sessions data automatically.
Session start
A session starts when a unique user has opened the app and initialized Leanplum (calling Leanplum.start
).
Session pause and resume
When the app is backgrounded, Leanplum will pause the session. When the app is re-opened, the session will resume. If the pause (background) lasts over 30 minutes, resuming the session will count as a new session.
See resumeSession for more on resume.
Session end
The session end is defined by 30 minutes or more inactivity after the app is backgrounded. If a user re-opens the app after backgrounding for 30 or more minutes, Leanplum will count this as a new session.
A session will also end if the app remains open but inactive for 2 or more hours. Force quitting the app (killing the app) also counts as a session end.
Session tracking in Analytics
Session info gets sent to Analytics as soon as the session ends, though it may take between 2-4 hours to see results come in. Note that sessions lasting longer than 8 hours will not count towards any duration statistics in Analytics — this is designed to prevent your duration results from being skewed by just a few outliers.
Offline event tracking
If events or states are tracked while a session is paused or closed, Leanplum will still track these events as part of an offline session. Events and states tracked during offline sessions will still count in Analytics.
Also note that if there are over 1500 events in a single session, the Analytics dashboard will truncate events over 1500. You can, however, view the full number of events in the user's profile in these cases.
See API limits for more information on our limits.
Web Session tracking
Our web SDK is more flexible in how you can manage your sessions and timestamps. By default, every time a new tab or window opens with your app, a new session will begin.
Depending on how long it has been since the user opened the app, you may want to track these new tabs as part of a single session. In order to do so, call the useSessionLength()
method before calling start()
:
Leanplum.useSessionLength(2 * 60 * 60); // 2 hours (in seconds)
Leanplum.start();
Calling this method stores the time of the last successful call in the browser localStorage. If the last call to start()
has occurred in less than this time, the session will be restored from cache by calling the startFromCache()
method internally.
NOTE:
Note that the JavaScript SDK tracks sessions differently than our mobile SDKs.