Skip to main content

Lifecycle Tracking (Android)

OpenCDP can automatically track application lifecycle events and screen views.

Configuration​

Enable lifecycle tracking in your OpenCDPConfig during initialization.

val config = OpenCDPConfig(
cdpApiKey = "YOUR_API_KEY",
autoTrackScreens = true, // Tracks Activity resumes as 'Screen Views'
trackApplicationLifecycleEvents = true, // Tracks 'App Opened' and 'App Backgrounded'
autoTrackDeviceAttributes = true // Automatically collects device model, OS, etc.
)

Automatic Screen Tracking​

When autoTrackScreens is set to true, the SDK uses ActivityLifecycleCallbacks to automatically record a screen view event whenever an Activity reaches the onResume state.

The screen name is derived from the Activity's class name, but you can override it if needed using manual tracking.

Lifecycle Events​

The following events are tracked automatically when trackApplicationLifecycleEvents is enabled:

Event NameDescription
application_openedTriggered when the app enters the foreground.
application_backgroundedTriggered when the app enters the background.
screen_viewTriggered when an Activity starts (recorded as a screen event).

Device Attributes​

When autoTrackDeviceAttributes is enabled, the SDK automatically collects and sends the following information:

  • Device Model
  • Manufacturer
  • OS Version
  • App Version
  • Screen Resolution
  • Locale