Skip to content

Apps

Android (Kotlin)

Privacy-first analytics for Android apps and games. Kotlin, zero third-party dependencies, Android 5.0+.

Overview

  • No ANDROID_ID, no advertising id, no device model, no install id — nothing persistent.
  • Nothing is written to the device (no SharedPreferences, no files, no database). Events and the session id live in memory only.
  • Events are batched and sent from a background thread with a neutral User-Agent: trackd-android/<version>. The SDK catches all errors and never crashes your app.

Requirements: minSdk 21 (Android 5.0), Kotlin 1.9+ / 2.x. Java callers are supported.

Install

The Maven Central artifact is coming. Until then:

  1. Download Trackd.kt and put it at app/src/main/java/one/trackd/sdk/Trackd.kt (keep the package or adjust the first line).
  2. Make sure your app manifest contains the internet permission — also for release builds. Without it no events are sent:
<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.INTERNET" />

Alternatively include the sdk/android/ folder as a Gradle module (include(":trackd"), implementation(project(":trackd"))).

Initialize

Initialize once in Application.onCreate(), then track screens and events:

import one.trackd.sdk.Trackd

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Trackd.init(this, "YOUR_WEBSITE_ID", debug = BuildConfig.DEBUG)
        // self-hosted: Trackd.init(this, "YOUR_WEBSITE_ID", host = "https://stats.example.com")
    }
}

Register the class in the manifest (<application android:name=".MyApp" …>). Events tracked before init stay in memory and are sent afterwards. In the dashboard, create a project with your application id (e.g. com.example.mygame) as domain.

Track purchases & revenue

Send revenue right after a successful purchase — with Google Play Billing in the PurchasesUpdatedListener, when the purchase state is PURCHASED:

override fun onPurchasesUpdated(result: BillingResult, purchases: List<Purchase>?) {
    if (result.responseCode != BillingClient.BillingResponseCode.OK || purchases == null) return
    for (purchase in purchases) {
        if (purchase.purchaseState == Purchase.PurchaseState.PURCHASED) {
            // Price from the ProductDetails, e.g. offer.priceAmountMicros / 1_000_000.0 and offer.priceCurrencyCode
            Trackd.revenue(4.99, "EUR", purchase.orderId)   // amount, currency, order id (optional)
        }
    }
}

Don’t send it when restoring purchases (queryPurchasesAsync) — a purchase would count twice. The event is called purchase and carries { amount, currency, order_id }. It shows up under Revenue and can be a funnel step: a Paywall → purchase funnel (screen view /paywall → event purchase) shows how many sessions with a paywall actually buy. The Analytics page calculates this conversion automatically once it detects a paywall screen, and Funnels has a template for it. Currencies and edge cases: Revenue tracking.

API

Trackd.init(
    context, websiteId,
    host = "https://trackd.one",
    debug = false,
    flushIntervalMs = 30_000,   // send at the latest 30 s after an event
    flushAt = 20,               // … or as soon as 20 events are queued
)

Trackd.screen("Home")                              // screen view (alias: screenView)
Trackd.screen("Settings/Profile", "Profile")       // with title
Trackd.event("signup", mapOf("plan" to "pro", "trial" to true))
Trackd.revenue(4.99, "EUR", "order-123")           // → event "purchase"
Trackd.flush()                                     // send now (async)
Trackd.setEnabled(false)                           // opt-out: stop + clear the queue

// Game & media helpers
Trackd.gameStart(level = 1, mode = "hard")
Trackd.levelComplete(level = 5, score = 1200, timeMs = 45_000)
Trackd.gameOver(level = 3, reason = "fell")
Trackd.videoWatch("intro", durationMs = 30_000, completed = true)
Trackd.adView("rewarded", "ad-1")
Trackd.tutorialStep(step = 2, total = 5, skipped = false)

Event data must be flat (String, Number, Boolean). Nested maps/lists, null and NaN/Infinity are dropped; the JSON is limited to 4 KB.

Screens with Jetpack Compose

@Composable
fun HomeScreen() {
    LaunchedEffect(Unit) { Trackd.screen("Home") }
}

// automatically for Navigation Compose
DisposableEffect(navController) {
    val listener = NavController.OnDestinationChangedListener { _, destination, _ ->
        // route templates like "profile/{id}" — never user data in screen names
        destination.route?.let { Trackd.screen(it.substringBefore('?')) }
    }
    navController.addOnDestinationChangedListener(listener)
    onDispose { navController.removeOnDestinationChangedListener(listener) }
}

With classic Activities/Fragments call Trackd.screen("Settings") in onResume().

Batching, retries & sessions

  • Flush at 20 queued events, 30 s after an event (both configurable), on flush() and when the app goes to the background.
  • Max. 50 events / 60 KB per request, max. 500 queued events (the oldest are dropped).
  • Network errors, 5xx, 408, 429 → exponential backoff (1 s … 5 min, honors Retry-After); the same batch is resent with the same batch_id, the server drops duplicates.
  • Session id: 20 random characters from SecureRandom, memory only, rotated after 30 minutes without events or 30 minutes in the background. Process end = new session.

Google Play Data safety

Declare App activity → App interactions (plus Other actions if you use revenue) and Location → Approximate location (country, derived server-side from the IP), purpose Analytics, not shared, encrypted in transit. Device or other IDs: not collected. These answers only describe the SDK — add whatever else your app collects.

Notes

  • ProGuard / R8: no keep rules needed.
  • Self-hosting via http:// is rejected by the server outside localhost; Android 9+ blocks cleartext traffic anyway. Use HTTPS.
  • If the system kills the app while events are queued, they are lost — the price of never writing analytics data to disk.
  • Whether your app needs consent has to be assessed for your app — see Privacy & GDPR.
App dashboard filtered to Android: users, sessions, screen views, screens and events
This is how your Android app appears in the dashboard (demo data, filter "Android").

Ready in minutes

Start the 7-day free trial (no credit card), add your website or app, copy the snippet.

Start free trial