Automatic Event Tracking
The SDK automatically tracks key lifecycle events without any code from you.
Automatically Tracked Events
first_open
Tracks when a user opens your app for the very first time after installation. Logged only once per device.
When it fires:
- First app launch after installation
- Only fires once per device lifetime
session_start
Tracks when a user starts a new session. A new session begins when the app comes to the foreground after being in the background longer than the session timeout period.
When it fires:
- App is opened from closed state
- App returns to foreground after session timeout (default: 30 minutes)
Customize session timeout:
B2MetricAnalyticsConfig(
apiKey = "YOUR_API_KEY",
assumedSessionTimeInMinutes = 15 // 15-minute timeout
)
session_end
Tracks when a user's session ends. Fires when the app remains in the background longer than the configured session timeout.
When it fires:
- Next time app comes to foreground after extended background time
How Sessions Work
The SDK uses Android's ProcessLifecycleOwner to automatically detect foreground/background transitions.
Session continuation (within timeout):
User opens app → session_start (session_id: "abc123")
User interacts for 10 minutes → Session continues
User backgrounds app for 5 min → Session still active (under 30-min timeout)
User returns to app → Same session continues (session_id: "abc123")
New session (timeout exceeded):
User opens app → session_start (session_id: "abc123")
User backgrounds app for 35 min → Session expires
User returns to app → session_end (session_id: "abc123", duration: 600s)
→ session_start (session_id: "def456")