Session Management (Flutter)
Automatic session tracking in mobile environments.
Overview
Mobile session tracking differs slightly from web. The Flutter SDK relies heavily on the WidgetsBindingObserver to listen for app lifecycle state changes.
Lifecycle Transitions
- Foreground (resumed): If the app has been in the background for more than 30 minutes and returns to the foreground, a new session is started, and a
$session_startevent is queued. - Background (paused): When the app is minimized, the SDK attempts to immediately flush the queue if the OS allows it. It records the timestamp to calculate the background duration later.
Offline Resilience
If a session occurs while the device is in airplane mode, the session ID is preserved along with all events. When connectivity is restored, the events are flushed with their original timestamps and original session IDs, ensuring your analytics remain perfectly accurate.