App Lifecycle Events
The Datafly mobile SDKs automatically track key app lifecycle events. This is enabled by default and can be disabled via the trackAppLifecycle configuration option.
Events tracked
Application Installed
Fired on the very first launch after install. Detected by checking for the absence of a stored app version.
{
"type": "track",
"event": "Application Installed",
"properties": {
"version": "2.1.0",
"build": "42"
}
}Application Updated
Fired on the first launch after an app update. Detected by comparing the stored version/build with the current values.
{
"type": "track",
"event": "Application Updated",
"properties": {
"version": "2.2.0",
"build": "45",
"previous_version": "2.1.0",
"previous_build": "42"
}
}Application Opened
Fired when the app enters the foreground.
{
"type": "track",
"event": "Application Opened",
"properties": {
"version": "2.2.0",
"build": "45",
"from_background": true
}
}The from_background property is false on cold launch and true when resuming from background.
Application Backgrounded
Fired when the app enters the background.
{
"type": "track",
"event": "Application Backgrounded",
"properties": {}
}Session management
The SDK maintains a session that tracks user engagement:
| Property | Description |
|---|---|
session.id | Epoch milliseconds when the session started |
session.number | Lifetime session count for this device |
session.is_new | true only on the first event of a new session |
A new session is created when:
- The app is launched for the first time
- The app returns to foreground after being backgrounded for longer than the session timeout (default 30 minutes)
Implementation details
iOS
The SDK observes UIApplication notifications:
willEnterForeground— triggers foreground logic + session checkdidEnterBackground— triggers background logic + records timestamp
Android
The SDK registers ActivityLifecycleCallbacks on the Application:
- Tracks an activity counter to determine foreground/background state
- Handles multi-activity apps correctly (only fires backgrounded when all activities are stopped)
No AndroidX Lifecycle dependency is required. The SDK uses the core ActivityLifecycleCallbacks API available since API 14.
Disabling lifecycle tracking
// iOS
let config = DataflyConfig(
pipelineKey: "dk_live_abc123",
endpoint: "https://data.example.com",
trackAppLifecycle: false
)// Android
val config = DataflyConfig(
pipelineKey = "dk_live_abc123",
endpoint = "https://data.example.com",
trackAppLifecycle = false
)When disabled, you can still manually track these events using track().