Documentation

Kotlin Multiplatform SDK.

Capture events, screens, links, and crashes from Android and desktop apps with one Kotlin library, with iOS to follow.

Kotlin Multiplatform

How the Kotlin Multiplatform SDK works

One Kotlin library for Android apps and desktop apps on the JVM, with iOS to follow. It sends the same events, people and sessions as your site's snippet, so an app and a site land in the same reports.

SettingValue
Packagecom.gotmode:metrics-kmp:0.1.1, from https://gotmode.com/sdk/maven
HostYour project's tracking hostname, such as https://m.example.com, from Setup
KeyYour project's public ingest key (mpk_), safe to ship inside an app
PlatformsAndroid 5.0 and later, desktop JVM 11 and later (Compose Desktop, Swing, JavaFX). iOS is not published yet
DeliveryA queue kept on the device, sent in batches of up to 50, retried with the same event ids so nothing is counted twice
Kotlin Multiplatform

Install

Add Mode's Maven repository, then the dependency, to your shared module or to an Android or desktop module on its own.

kotlin
// settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        exclusiveContent {
            forRepository { maven("https://gotmode.com/sdk/maven") }
            filter { includeGroup("com.gotmode") }
        }
    }
}
kotlin
// build.gradle.kts
kotlin {
    sourceSets {
        androidMain.dependencies { implementation("com.gotmode:metrics-kmp:0.1.1") }
        jvmMain.dependencies { implementation("com.gotmode:metrics-kmp:0.1.1") }
    }
}

Two optional parts for Android are packages of their own, so an app that does not use them carries none of their code. Add each one you use next to the core.

kotlin
// build.gradle.kts of the Android app
dependencies {
    implementation("com.gotmode:metrics-kmp-navigation:0.1.1")       // Jetpack Navigation screens
    implementation("com.gotmode:metrics-kmp-installreferrer:0.1.1")  // the Play Install Referrer
}

The repository has the Android and desktop JVM builds. The iOS build is not in it yet, so add the dependency to your Android and desktop source sets, and use the Apple SDK in the iOS app for now.

Mode serves its SDKs itself, not from a public package registry. A published version never changes, and every file and its SHA-256 is listed in SHA256SUMS.

FileVersionSHA-256
metrics-kmp-0.1.1.jar0.1.112bd0703692ebf90d7d4fb10e433bab563c78e54d2509147e1390be4b551d93d
metrics-kmp-jvm-0.1.1.jar0.1.166194add8f577f51eddec7969879750ff1ffcdd8d20d9e4070a254c8b6b37154
metrics-kmp-android-0.1.1.aar0.1.161dda33c9b1a92f330a411d0e8f249f20538ff5b77741a5a0a355d5a89dea272
metrics-kmp-navigation-0.1.1.aar0.1.1a6fb183865706c84450499816ff87ca6ea25342302d6f55e0215fa3cdecd877a
metrics-kmp-installreferrer-0.1.1.aar0.1.1d7ef3ba42605158cbe2b5482a47fabe220f7b91e4c698b9fac9a335b4a5fe983

The SDK asks for no Android permission beyond INTERNET and brings no Firebase or Navigation library. The install referrer package brings Google's Play Install Referrer library, and the navigation package uses your app's own Navigation.

Kotlin Multiplatform

Android

Call setup once in your Application. Install, update, opens, backgrounds, screens, deep links, notification taps and permission, the Firebase token, taps on views and on Jetpack Compose, and crashes are captured from then on.

kotlin
class App : Application() {
    override fun onCreate() {
        super.onCreate()
        ModeMetrics.setup(this, "YOUR_INGEST_KEY", ModeOptions().apply {
            apiHost = "https://m.example.com"
        })
    }
}

A link that reaches an activity already running arrives in onNewIntent. Pass it on with ModeMetrics.handleIntent(intent). For Jetpack Navigation, in Compose or with fragments, ModeNavigation.track(navController) from metrics-kmp-navigation sends a $screen for every destination.

Kotlin Multiplatform

Desktop

Call setup with your app's id at start. Data is kept in the user's preferences under that id.

kotlin
ModeMetrics.setup("com.example.notes", "YOUR_INGEST_KEY", ModeOptions().apply {
    apiHost = "https://m.example.com"
    appVersion = "1.4.0"
})
ModeMetrics.trackWindow(window, "main")  // optional, names a window's id

$app_opened is sent at start and $app_quit when the app exits, waiting at most 2 seconds for the send. In Compose Desktop and Swing every window's events and every click on a control are captured with no more code. JavaFX and other toolkits report windows with windowOpened, windowClosed, windowFocused, and windowBlurred. The platform is read from the system as macos, windows, or linux.

Kotlin Multiplatform

iOS

From Swift, through the framework your shared module builds.

Not available yet. The iOS build of this library isn't published, so a shared module can't ship it to an iOS app today. Use the Apple SDK in the iOS app for now. Its setup will be listed here once the iOS build is published.
Kotlin Multiplatform

Events, people and groups

The same calls on every platform.

kotlin
ModeMetrics.capture("Order Completed", mapOf("total" to 42.5))
ModeMetrics.screen("Cart")
ModeMetrics.identify("user_42", set = mapOf("plan" to "pro"))  // after sign in
ModeMetrics.group("company", "acme")
ModeMetrics.register(mapOf("theme" to "dark"))    // on every event
ModeMetrics.reset()                                  // on sign out

Also alias, setPersonProperties, unsetPersonProperties, registerOnce, registerForSession and unregister. A different user signing in on the same device becomes a new person, never a merge. Person properties set before sign in are sent with the next identify. An empty id or a placeholder such as null or anonymous is dropped.

Kotlin Multiplatform

Push notifications

Tokens, notification opens, and notification permission are captured automatically when the platform provides them. The SDK never depends on a push library.

On iOS the APNs token, notifications received and tapped, and the permission come from the app delegate and the notification center's delegate. On Android a tap on a Firebase notification is read from the launch. On each return to the app, the SDK checks notification permission and, while analytics is allowed, reads the available Firebase token when your app ships Firebase Messaging with automatic token creation on. A message that arrives while an Android app runs reaches only your messaging service, so pass it on there. Forward refreshed Firebase tokens from onNewToken for immediate updates.

kotlin
override fun onMessageReceived(m: RemoteMessage) = ModeMetrics.pushReceived(m.data)
override fun onNewToken(token: String) = ModeMetrics.registerPushToken(token, "fcm")

Each notification gives only its message id, campaign, category, thread, and channel, never its title or body. A token is sent once until it changes, and the token itself only when you set sendPushToken.

Kotlin Multiplatform

Errors and logs

Crashes are captured on every platform and saved before the app stops, then sent on the next start.

kotlin
ModeMetrics.captureException(error, mapOf("step" to "pay"))
ModeMetrics.log("warn", "payment retried")

Each error carries its type, message, stack, whether it was handled or fatal, the release and the last 20 events before it, and appears in Errors. At most 50 are sent a run. Logs go to the logs store, scrubbed of emails and long numbers. Set console = true to also send what an Android or desktop app prints.

Kotlin Multiplatform

Feature flags

Flags load at start and whenever the person changes, and are cached for the next start.

kotlin
ModeOptions().apply { flags = true }
if (ModeMetrics.isFeatureEnabled("new-checkout")) showNewCheckout()
Kotlin Multiplatform

What is captured automatically

Every family can be turned off with disabledAutocapture, or all of them with autocapture = false, and from your project's settings.

EventAndroidDesktopiOS, once published
$app_installed, $app_updatedYesYesYes
$app_opened, $app_backgroundedYesOpened at startYes
$app_quitYes
$screenActivities and NavigationWith screenView controllers, SwiftUI screens, and Compose screens
$deep_link_openedYesYes, universal links too
$click, $rage_clickTaps on views and ComposeClicks in Swing and Compose DesktopTaps on controls, cells, and SwiftUI buttons
$push_registered, $push_opened, $push_receivedFirebase token and opensYes
$permission_change for notificationsYesYes
$window_opened, $window_closed, $window_focus, $window_blurEvery Swing and Compose window
$exceptionYesYesYes

The first event of each session carries the device (OS, model, type, pixel ratio, dark mode, text size, reduced motion, build, and languages), never anything typed or stored. The text of a tapped control is scrubbed of emails and long numbers and cut to 80 characters, left out entirely with maskText, and a text or password field never sends its text. A Compose control is described from its semantics, its role, its text or content description, and its test tag.

Let AI run your marketing.

Mode Agent does the daily work. You approve the spend.

Get early access