Install the Kotlin library and send your first private 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.
Install the Android library
Install the tagged public release through JitPack. Maven Central remains an optional future mirror.
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven(url = "https://jitpack.io")
}
}// app/build.gradle.kts
dependencies {
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.Application
import com.appmetricskit.AppMetricsConfig
import com.appmetricskit.AppMetricsKit
class ExampleApp : Application() {
override fun onCreate() {
super.onCreate()
AppMetricsKit.configure(
context = this,
config = AppMetricsConfig(
ingestUrl = "https://appmetricskit.com/api/ingest",
ingestKey = "amk_live_...",
testMode = false,
allowedPayloadKeys = setOf("plan", "source", "price", "errorCode"),
blockedPayloadKeys = setOf("email", "phone", "name"),
collectionEnabled = true, // Replace with your persisted consent state.
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.
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, retried for network failures, and protected by stable event IDs for safe retries. 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. Calling identify(userId) also sends a stable SHA-256 hash that remains pseudonymous data and may need to be disclosed as a user ID. Your final answers must also cover custom payloads, retention, and all other SDKs in the app.