Skip to content

Kotlin SDK

Official Kotlin SDK for Mitr Analytics — native Android, minSdk 21+.

Install

Not yet published to Maven Central — add it as a local Gradle module dependency:

// settings.gradle.kts
includeBuild("../mitr-sdk-suite/mitr-kotlin") // adjust to your project layout

// app/build.gradle.kts
dependencies {
    implementation(project(":mitr-kotlin:android"))
}

Get your Site ID and Secret Key

From the dashboard: Integration Hub → Add New App → Android. You'll get a Site ID and a Secret Key — copy the secret key now, it's shown in full only once. Android apps have no browser Origin to check, so the secret key is sent with every request instead.

Initialize

import dev.mitranalytics.sdk.android.MitrAnalytics
import dev.mitranalytics.sdk.core.MitrAnalyticsOptions

val mitr = MitrAnalytics(
    context = applicationContext,
    options = MitrAnalyticsOptions(siteId = "YOUR_SITE_ID", secretKey = "YOUR_SECRET_KEY"),
)

MitrAnalytics(context, options) is a factory function, not a constructor — it wires up MitrAnalyticsCore with SharedPreferences persistence and real device info automatically.

Manual tracking

Every method is suspend — call from a coroutine:

lifecycleScope.launch {
    mitr.track("purchase_completed", metadata = mapOf("value" to 49.99, "currency" to "USD"))
    mitr.pageView("HomeScreen")
}

Identifying users (login/logout)

// After a successful login:
mitr.identify(user.id)

// On logout:
mitr.reset()

User ids are SHA-256 hashed on-device (via MessageDigest) before they're ever sent — the backend only ever sees user_hash.

Deep-link attribution

Kotlin has no SDK-level hook into app lifecycle, so feed deep links to the SDK yourself from your Activity's intent handling (onCreate/onNewIntent):

lifecycleScope.launch { mitr.captureDeepLink(intent.dataString ?: "") }

First-touch semantics: only the first utm_*-bearing URL you pass in is kept.

Resilience

Events are batched (flushed every 5s or every 10 events, whichever comes first) and persisted to SharedPreferences between flushes — an app kill doesn't lose queued events.

Have questions about integration or security? Drop us a line directly.