Skip to main content

Android SDK

A lightweight Android SDK for tracking analytics events.

Requirements

  • Android SDK 21+ (Android 5.0 Lollipop)
  • Kotlin 1.9+

Installation

Gradle (Kotlin DSL)

dependencies {
implementation("com.github.Mostly-Good-Metrics:mostly-good-metrics-android-sdk:1.0.0")
}

Add JitPack repository to your settings.gradle.kts:

dependencyResolutionManagement {
repositories {
maven { url = uri("https://jitpack.io") }
}
}

Quick Start

Initialize

Initialize once in your Application class:

class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
MostlyGoodMetrics.configure(this, "mgm_proj_your_api_key")
}
}

Track Events

// Simple event
MostlyGoodMetrics.track("button_clicked")

// Event with properties
MostlyGoodMetrics.track("purchase_completed", mapOf(
"product_id" to "SKU123",
"price" to 29.99,
"currency" to "USD"
))

Identify Users

// Set user identity
MostlyGoodMetrics.identify("user_123")

// Reset identity (e.g., on logout)
MostlyGoodMetrics.resetIdentity()

Configuration Options

val config = MGMConfiguration.Builder("mgm_proj_your_api_key")
.baseUrl("https://mostlygoodmetrics.com")
.environment("production")
.maxBatchSize(100)
.flushIntervalSeconds(30)
.maxStoredEvents(10000)
.enableDebugLogging(BuildConfig.DEBUG)
.trackAppLifecycleEvents(true)
.build()

MostlyGoodMetrics.configure(this, config)
OptionDefaultDescription
apiKeyRequiredYour API key
baseUrlhttps://mostlygoodmetrics.comAPI endpoint
environment"production"Environment name
maxBatchSize100Events per batch (1-1000)
flushIntervalSeconds30Auto-flush interval
maxStoredEvents10000Max cached events
enableDebugLoggingfalseEnable logcat output
trackAppLifecycleEventstrueAuto-track lifecycle events

Automatic Events

EventWhenProperties
$app_installedFirst launch after install$version
$app_updatedFirst launch after version change$version, $previous_version
$app_openedApp became active (foreground)-
$app_backgroundedApp resigned active (background)-

Automatic Context

Every event automatically includes:

FieldExampleDescription
platform"android"Platform
os_version"14"Android version
app_version"1.0.0 (42)"App version with build number
session_id"uuid..."Unique session ID
user_id"user_123"User ID (if set)
$device_type"phone"Device type (phone, tablet, tv, watch)
$device_model"Pixel 8"Device model

Java Interop

// Initialize
MostlyGoodMetrics.configure(context, "mgm_proj_your_api_key");

// Track
Map<String, Object> props = new HashMap<>();
props.put("button_name", "submit");
MostlyGoodMetrics.track("button_clicked", props);

// Identify
MostlyGoodMetrics.identify("user_123");

ProGuard / R8

The SDK includes consumer ProGuard rules. No additional configuration needed.