How the Android SDK works
One library for Android apps, in Kotlin and usable from Java. Set it up once and installs, opens, screens, taps, links, notifications, Play purchases, crashes and ANRs are captured with no other code.
| Setting | Value |
|---|---|
| Host | Your project's tracking hostname, such as https://m.example.com, from Setup |
| Key | The ingest key (mpk_) of an Android source, from Setup. It ships in the app, so it can only send events. |
| Systems | Android 5.0 (API 21) or later |
| Delivery | Queued on the device, sent every 10 seconds, at 50 events and when the app goes to the background, retried with the same event ids so nothing is lost or counted twice |
Install and set up
Once the library is published, add it to your build and call setup in your Application.
class App : Application() { override fun onCreate() { super.onCreate() Mode.setup(this, ModeConfig.Builder("YOUR_INGEST_KEY", "https://m.example.com").build()) } }
From Java the same call is Mode.setup(this, ModeConfig.builder("YOUR_INGEST_KEY", "https://m.example.com").build()).
What is captured on its own
Every event lands in the same reports as your site's and your iOS app's, with the same people and sessions.
| Event | When |
|---|---|
$app_installed | The first launch, with the version and build and the Play Install Referrer, so its campaign and the Mode click id reach every later event |
$app_updated | The first launch of a new version or build, with the previous one |
$app_opened | A cold launch, with how long it took to start, and every return to the foreground, with how long the app was away and the link or notification that opened it |
$app_backgrounded | The app left the screen, with how long it was in use |
$screen | An activity or fragment appeared, or a Navigation destination changed, with the screen before it and how long it was shown |
$click, $rage_click | A tap on a button, switch, check box, list row or Compose control, and three fast taps in one place |
$deep_link_opened | An App Link or a custom scheme link opened the app, with the app that sent it. Its UTM parameters, the Mode click id and sub ids are kept, so later signups and purchases are credited to the campaign |
$push_received, $push_opened | A notification arrived, or the person opened one, with its message id, campaign and channel |
$push_registered, $permission_change | The app got a push token, and notifications were turned on or off |
$purchase, $subscription_started | Google Play purchases and subscriptions, each stored once even when Google's notifications report it too |
$exception | Crashes, ANRs and, on Android 11 and later, the last run's native crashes and system ANRs, with the screens and events before them |
The first event of each session also carries the device (model, Android version, display, dark mode, text size, battery, network and the store the app came from). Every event carries the screen it happened on.
Compose navigation and notifications
Two one line hookups cover what Android does not let a library find on its own.
val nav = rememberNavController()
LaunchedEffect(nav) { Mode.trackNavController(nav) }For notifications, register com.gotmode.metrics.ModeMessagingService as your Firebase messaging service, or call Mode.pushReceived(message) and Mode.registerPushToken(token) from your own. Notifications Firebase shows itself are seen when they open the app.
Your own events and people
Add what only your app knows, and tie the device to the person once they sign in.
Mode.capture("order_placed", mapOf("plan" to "pro", "items" to 3)) Mode.identify("user_123", set = mapOf("plan" to "pro")) Mode.group("company", "acme") Mode.register(mapOf("app_flavor" to "pro")) Mode.reset() // on sign out
A different user on the same device starts a new person, two users are never merged. setPersonProperties and unsetPersonProperties change the person before or after sign in, and registerOnce and registerForSession keep properties on every event, once or for the session.
Consent and opting out
Wait for the person's answer before anything is stored, or start everyone opted out.
Mode.setup(this, ModeConfig.Builder("YOUR_INGEST_KEY", "https://m.example.com") .consent(ModeConsent.PENDING) // hold events in memory until setConsent .build()) Mode.setConsent(ModeConsent.GRANTED) Mode.optOut() // stops capture and deletes the queue, remembered across launches
With ad storage denied, ad click ids and the Mode click id are left out of every event.
Feature flags
Read your project's flags in the app. They load at launch, after sign in and after group and property changes, and are kept for the next launch.
if (Mode.isFeatureEnabled("new-checkout")) { ... } val variant = Mode.getFeatureFlag("price-test") as? String Mode.onFeatureFlags { flags -> ... }
Purchases
When your app uses Play Billing, purchases are read on their own each time the app opens. To record one the moment it happens, and for consumables, pass it from your purchase listener too. It is still stored once.
override fun onPurchasesUpdated(result: BillingResult, purchases: List<Purchase>?) {
purchases?.forEach { Mode.capturePurchase(it) }
}What is never sent
The SDK collects what the app does, not what people type or keep.
Never sent, the content of any text field, notification titles and bodies, the advertising id, accounts, phone numbers, purchase tokens, or a property whose name reads as a secret. Links lose sign in tokens, codes, passwords and keys before they are kept, and email addresses become [email].