Browse docs

Explore by section, then jump directly into a page.

Kotlin SDK

Integrate the FlashAnalytics Kotlin SDK in native Android apps.

Use the Kotlin SDK for native Android apps when you want app lifecycle, screen tracking, deep links, notification lifecycle, native crash capture, and experiment assignment in a native integration.

Install

dependencies {
  implementation("app.flashanalytics:flashanalytics-kotlin:1.0.9")
}

Application setup

class MyApp : Application() {
  override fun onCreate() {
    super.onCreate()

    FlashAnalyticsAndroid.init(
      application = this,
      options = FlashAnalyticsOptions(
        appId = "YOUR_APP_ID",
        endpoint = "https://api.flashanalytics.app",
        captureAppLifecycle = true,
        captureScreenViews = true,
        captureDeepLinks = true,
        capturePushLifecycle = true,
        captureNativeCrashes = true,
        captureVariants = CaptureVariantsOptions(
          modes = setOf(
            AutoExperimentAssignmentMode.SESSION,
            AutoExperimentAssignmentMode.PROFILE,
          )
        ),
        defaultNotificationTtlMs = 300_000L,
      )
    )
  }
}

Auto capture

  • App lifecycle via captureAppLifecycle
  • Screen views via captureScreenViews
  • Deep links via captureDeepLinks
  • Native crashes via captureNativeCrashes or captureErrors
  • Experiment auto-assignment via captureVariants
  • Push lifecycle helpers via capturePushLifecycle

Manual error tracking

try {
  riskyOperation()
} catch (e: Exception) {
  FlashAnalyticsAndroid.getInstance().trackError(
    throwable = e,
    eventName = "payment_failed",
    properties = mapOf("orderId" to orderId),
  )
}

Notification lifecycle

The SDK supports delivered, opened, dismissed, action-clicked, and expired events. Android still needs receiver registration, notification intents, and payload forwarding from the host app.

analytics.trackNotificationEvent(
  event = FlashNotificationEvent.OPENED,
  intent = intent,
  source = "android_intent",
  appState = "terminated",
  coldStart = true,
)

Session access

val session = analytics.getSession()
println(session?.id)
println(session?.estimatedExpiresAt)
println(session?.estimatedTtlMs)