Skip to main content

Install on Android with Kotlin

Use the Kotlin SDK when your product is a native Android app. It is a Gradle library built on OkHttp, with no other required dependencies beyond AndroidX Process Lifecycle. Enable Mobile apps traffic during Create your first property before sending events.

Install

dependencies {
implementation("to.nexly:nexly-android:1.0.0")
}

Initialize

Call Nexly.init once from your Application.onCreate:

import to.nexly.Nexly

class MyApp : Application() {
override fun onCreate() {
super.onCreate()
Nexly.init(this, appId = "your-app-id", key = "your-ingest-key")
}
}

Use the App ID and Ingest key from Settings → Installation. Do not use a personal API token for SDK collection.

Track screens and events

Send a screenview when the visible screen changes:

Nexly.screenview("Settings")

Emit custom events from anywhere in the app:

Nexly.customEvent(
"checkout_started",
cdata = mapOf("cart_value_cents" to 4200),
)

Engagement tracking (active seconds, heartbeats, session end) is driven automatically by app lifecycle callbacks, matching the React Native, Swift, and Flutter SDKs' behavior.

Privacy mode and identity

The Kotlin SDK supports the same privacy mode as the other SDKs: when enabled, it never reads or writes on-device storage for the visitor and session IDs. Like the Swift and Flutter SDKs, it can be toggled at runtime — useful for a consent switch in your settings screen:

Nexly.setPrivacyMode(true)

You can also override the visitor or session ID, for example to link app events to an identity your backend already knows:

Nexly.setVisitorId("your-visitor-id")
Nexly.setSessionId("your-session-id")

Changes take effect on the next event; no reinitialization is needed.

Allowed origins

Android traffic uses a dedicated SDK traffic source instead of a browser origin. Enable Mobile apps in Settings → Ingest so the collector accepts events from the SDK. See Ingest settings for details.

Verification

Use the events feed to confirm events arrive with the Kotlin (Android) source. The Technology widget shows this traffic as browser Kotlin on Android mobile devices.