Install the Kotlin library and send your first analytics event.
Use the official AppMetricsKit Android library to capture onboarding, paywall, purchase, subscription, and app-health events without sending raw account IDs, advertising IDs, or cross-app identifiers.
Implement the complete Android integration
Copy a repository aware prompt covering architecture, consent, identity, revenue events, privacy, tests, and release verification.
Install the Android library
Install the tagged public release through JitPack. Maven Central remains an optional future mirror.
// settings.gradle.ktsdependencyResolutionManagement { repositories { google() mavenCentral() maven(url = "https://jitpack.io") }}// app/build.gradle.ktsdependencies { implementation("com.github.appmetricskit:appmetricskit-android-kotlin:v0.1.1")}Library details
- Repository
- appmetricskit/appmetricskit-android-kotlin
- Maven coordinate
- com.github.appmetricskit:appmetricskit-android-kotlin:v0.1.1
- Minimum SDK
- Android API 23+
Configure once in your Application
Generate an ingest key in AppMetricsKit, then configure the SDK with your deployed ingest endpoint. If your app already has an Application subclass, configure the SDK there instead of creating a second one.
import android.app.Applicationimport com.appmetricskit.AppMetricsConfigimport com.appmetricskit.AppMetricsKit
class ExampleApp : Application() { override fun onCreate() { super.onCreate()
// Read this value from your app's persisted consent state. val analyticsConsentGranted = false
AppMetricsKit.configure( context = this, config = AppMetricsConfig( ingestUrl = "https://appmetricskit.com/api/ingest", ingestKey = "amk_live_...", testMode = false, allowedPayloadKeys = setOf( "plan", "source", "productId", "basePlanId", "billingResponse", "price", "errorCode", ), collectionEnabled = analyticsConsentGranted, automaticAppLaunchTracking = false, ), ) }}Register a new Application subclass in the host application manifest:
<!-- AndroidManifest.xml --><application android:name=".ExampleApp"> <!-- Existing activities and providers --></application>Track events
Event names use Namespace.action. The SDK hashes user IDs on device before sending them as anonymousUserId. Track the launch after identification when retention must use a stable account hash.
// Call after the user grants analytics consent.AppMetricsKit.setCollectionEnabled(true)AppMetricsKit.identify(userId = user.id)AppMetricsKit.trackAppLaunch()
AppMetricsKit.track( eventName = "Paywall.viewed", payload = mapOf("plan" to "pro_monthly", "source" to "onboarding"),)
AppMetricsKit.track( eventName = "Purchase.completed", payload = mapOf("plan" to "pro_monthly"), floatValue = 29.99,)Built-in helpers
Use helper methods for the event names that power AppMetricsKit dashboards.
AppMetricsKit.trackAppLaunch()AppMetricsKit.trackOnboardingStarted()AppMetricsKit.trackOnboardingCompleted()AppMetricsKit.trackPaywallViewed(plan = "pro_monthly")AppMetricsKit.trackPurchaseCompleted(plan = "pro_monthly", amount = 29.99)AppMetricsKit.trackError(name = "network_timeout")Privacy defaults
- Raw user IDs are hashed on device with SHA-256.
- Payloads are flat string, number, or boolean values only.
- Blocked keys such as email, phone, name, IP, location, device ID, and advertising ID are dropped.
- Values that look like email addresses, phone numbers, or card numbers are dropped.
Offline queue and flushing
Events are persisted under the app files directory, batched, and protected by stable event IDs. The SDK retries network failures, HTTP 408, HTTP 429, and HTTP 5xx responses. Other non-success responses are treated as permanent and dropped so they cannot block the queue. Normal manual flushes are asynchronous.
// Returns immediately and flushes on the SDK background executor.val pendingFlush = AppMetricsKit.flush()
// flushBlocking() is only for worker or test threads. Never call it on the UI thread.Consent and collection
Initialize collectionEnabledfrom the app's persisted consent state. Disabling collection rejects new events, purges queued events, and resets the in-memory account hash. A network request that was already in flight may still complete.
// Disabling collection purges queued events and the in-memory identity.AppMetricsKit.setCollectionEnabled(false)
// Identify again after the user opts back in.AppMetricsKit.setCollectionEnabled(true)AppMetricsKit.identify(userId = user.id)Google Play Data Safety
Disclose AppMetricsKit in the host app's Data Safety form. The SDK sends app interactions and event context for analytics. Event context includes app version and build, OS version, device model, locale, timezone, and random session and event IDs. Calling identify(userId) also sends a stable SHA-256 hash that remains pseudonymous data and may need to be disclosed as a user ID. The SDK does not collect the advertising ID, a raw device identifier, or the raw account ID by default. Your final answers must also cover custom payloads, retention, all other SDKs in the app, and whether metadata or random IDs require another applicable disclosure.