A Kotlin Multiplatform (KMP) wrapper for Amplitude Analytics that provides a unified API for Android and iOS platforms.
- ✅ Android (API 21+)
- ✅ iOS (12.0+)
- iOS x64
- iOS ARM64
- iOS Simulator ARM64
KMP-Amplitude is published on GitHub Packages. You need a GitHub token to download it (one-time setup):
- Go to GitHub Settings → Personal access tokens
- Generate new token (classic)
- Select scope:
read:packages - Copy the token
Add to ~/.gradle/gradle.properties:
gpr.user=YOUR_GITHUB_USERNAME
gpr.key=YOUR_PERSONAL_ACCESS_TOKENsettings.gradle.kts:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
name = "kmp-amplitude"
url = uri("https://maven.pkg.github.com/OneXeor/kmp-amplitude")
credentials {
username = providers.gradleProperty("gpr.user").orNull
password = providers.gradleProperty("gpr.key").orNull
}
}
}
}build.gradle.kts:
kotlin {
// ...
sourceSets {
// ...
commonMain.dependencies {
implementation("dev.onexeor:kmp-amplitude:1.0.0")
}
}
}val amplitude = KmpAmplitude.configure(
KmpAmplitudeConfiguration(
apiKey = "YOUR_API_KEY",
userId = "user-123", // Optional
flushIntervalMillis = 50000,
flushQueueSize = 20
)
)// Simple event
amplitude.logEvent("button_clicked")
// Event with properties
amplitude.logEvent(
eventName = "purchase_completed",
properties = mapOf(
"product_id" to "12345",
"price" to 29.99,
"currency" to "USD"
)
)// Set user ID
amplitude.setUserId("user-123")
// Set user properties
val identify = KmpAmplitudeIdentify()
.set("email", "user@example.com")
.set("subscription_tier", "premium")
.add("login_count", 1)
amplitude.identify(identify)Main class for tracking events and managing users.
fun configure(configuration: KmpAmplitudeConfiguration): KmpAmplitudeCreates and configures an Amplitude instance.
-
logEvent(eventName: String, properties: Map<String, Any?>? = null)
Tracks an event with optional properties. -
identify(identify: KmpAmplitudeIdentify, outOfSession: Boolean = false)
Updates user properties. -
setUserId(userId: String?, startNewSession: Boolean = false)
Sets or updates the user ID.
Configuration options for Amplitude.
data class KmpAmplitudeConfiguration(
val apiKey: String,
val userId: String? = null,
val flushIntervalMillis: Int = 50000,
val flushQueueSize: Int = 20
)Builder for user property operations.
set(property: String, value: Any?)- Set a user property valuesetOnce(property: String, value: Any?)- Set only if not already setadd(property: String, value: Any?)- Increment a numeric propertyunset(property: String)- Remove a user propertyremove(property: String, value: Any?)- Remove value from array propertyprepend(property: String, value: Any?)- Prepend to array propertypostInsert(property: String, value: Any?)- Append to array propertypreInsert(property: String, value: Any?)- Prepend to array propertyclearAll()- Clear all user properties
amplitude.logEvent(
eventName = "user_signup",
properties = mapOf(
"method" to "email",
"referral_source" to "google"
)
)
val identify = KmpAmplitudeIdentify()
.set("email", "newuser@example.com")
.set("signup_date", System.currentTimeMillis())
.setOnce("first_platform", "android")
amplitude.identify(identify)amplitude.logEvent(
eventName = "purchase",
properties = mapOf(
"product_name" to "Premium Subscription",
"price" to 9.99,
"currency" to "USD",
"quantity" to 1
)
)
val identify = KmpAmplitudeIdentify()
.add("total_revenue", 9.99)
.add("purchase_count", 1)
.set("subscription_status", "active")
amplitude.identify(identify)- Kotlin 2.2.20 or higher
- Android: minSdk 21
- iOS: deployment target 12.0
- Gradle 9.1.0 or higher
# Clone the repository
git clone https://github.com/OneXeor/kmp-amplitude.git
cd kmp-amplitude
# Build the library
./gradlew build
# Run tests
./gradlew testContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Kotlin Multiplatform
- Uses Amplitude Analytics SDKs
- Android SDK: amplitude-android
- iOS SDK: Amplitude-iOS
- 📧 Email: support@onexeor.dev
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
See CHANGELOG.md for a list of changes in each version.
Made with ❤️ by OneXeor