Add analytics to Android (Kotlin) Android (Kotlin).
Android analytics means logging screen changes and taps from your native Kotlin app. smolanalytics has no Android SDK. You send events with an OkHttp POST to /v1/events, a few lines and a client you probably already ship. Batch them to save battery, then ask your numbers in plain English from the dashboard or your editor.
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
object Analytics {
private const val host = "https://YOUR-INSTANCE"
private const val key = "WRITE_KEY"
private val client = OkHttpClient()
private val json = "application/json".toMediaType()
fun track(name: String, distinctId: String, properties: Map<String, Any> = emptyMap()) {
val payload = JSONObject(mapOf(
"name" to name, "distinct_id" to distinctId, "properties" to JSONObject(properties)))
val req = Request.Builder().url("$host/v1/events")
.addHeader("Authorization", "Bearer $key")
.post(payload.toString().toRequestBody(json)).build()
client.newCall(req).enqueue(object : Callback {
override fun onFailure(call: Call, e: java.io.IOException) {}
override fun onResponse(call: Call, response: Response) { response.close() }
})
}
}
// batch: POST a JSON array to /v1/events to cut requestsNo native SDK. Uses OkHttp, standard on Android, and enqueue keeps it off the main thread. Call track from onResume or your nav destination listener.
how do I add analytics to android (kotlin)?
Android analytics means logging screen changes and taps from your native Kotlin app. smolanalytics has no Android SDK. You send events with an OkHttp POST to /v1/events, a few lines and a client you probably already ship. Batch them to save battery, then ask your numbers in plain English from the dashboard or your editor.
Call track() from a lifecycle onResume or a Navigation OnDestinationChangedListener so each screen logs a screen_view with the destination in properties, and fire it on the taps that matter (signup, checkout, share). Pass a stable distinct_id, the user id after login or an install id before, so funnels and retention collapse to one real person.
Mobile radios love fewer wakeups, so batch. Buffer events in a list and flush a single JSON-array POST to /v1/events on an interval or in onStop when the app backgrounds. Same endpoint and write key as your web and backend, so it all lands together and you can just ask, in plain English, where users drop off, backed by a report that a CI test proves cannot be hallucinated.
Honest pricing: 14-day full trial, no credit card. Then Solo $29/mo, never metered on seats or sites. Overage is $5/million with an emailed receipt, the dashboard never locks, and self-hosting the single Go binary is free forever (MIT).
Add analytics to Android (Kotlin) tonight.
One snippet, or one endpoint. Tomorrow morning the verdict tells you which part of the funnel to fix.