Skip to Content
DocsSDKsAndroidOverview

Android SDK

Coming soon

Native Android SDK for Kotlin and Java applications with automatic lifecycle tracking and session management.

Interim integration

Send events via the Connect RPC API until the native SDK ships.

Add dependencies

// build.gradle.kts dependencies { implementation("com.squareup.okhttp3:okhttp:4.12.0") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0") }

Track events

import okhttp3.* import kotlinx.serialization.json.* import java.time.Instant class PugClient( private val projectId: String, private val apiKey: String, private val endpoint: String = "https://api.pug.sh" ) { private val client = OkHttpClient() private val json = Json { ignoreUnknownKeys = true } fun track(eventName: String, properties: Map<String, Any> = emptyMap()) { val payload = buildJsonObject { putJsonArray("events") { addJsonObject { put("name", eventName) putJsonObject("properties") { properties.forEach { (k, v) -> put(k, v.toString()) } } put("timestamp", Instant.now().toString()) } } } val request = Request.Builder() .url("$endpoint/events.v1.EventsService/BatchCreate") .addHeader("Authorization", "Bearer $apiKey") .addHeader("x-project-id", projectId) .addHeader("Content-Type", "application/json") .addHeader("Connect-Protocol-Version", "1") .post(payload.toString().toRequestBody("application/json".toMediaType())) .build() client.newCall(request).enqueue(object : Callback { override fun onFailure(call: Call, e: java.io.IOException) { // Handle silently — analytics should not crash the app } override fun onResponse(call: Call, response: Response) { response.close() } }) } } // Usage val pug = PugClient(projectId = "YOUR_PROJECT_ID", apiKey = "YOUR_SDK_API_KEY") pug.track("app_open") pug.track("purchase", mapOf("revenue" to 29.99, "currency" to "USD", "order_id" to "ord-123"))

Planned features

  • Gradle dependency, minimal setup
  • Automatic Activity lifecycle and session tracking
  • Background batch flush with WorkManager
  • ProGuard/R8 rules included
  • Generated Kotlin client from proto

Further reading

Last updated on