
Unified, type-safe Mixpanel analytics wrapper offering a single API for tracking events, properties and purchases, with simple initialization and flexible event/property mapping.
A Kotlin Multiplatform library for integrating Mixpanel analytics across Android and iOS platforms.
mixpanel-kmp provides a unified, type-safe API for tracking analytics events with Mixpanel across Android and iOS. Built with Kotlin Multiplatform, it allows you to write your analytics tracking logic once and deploy it on both mobile platforms.
Note: This library is a Kotlin Multiplatform wrapper around the native Mixpanel SDKs for Android and iOS. It depends on the official Mixpanel SDK for Android and the Mixpanel SDK for iOS under the hood.
Add the dependency to your build.gradle.kts:
commonMain {
dependencies {
implementation("io.github.itsivag:mixpanel-kmp:<latest-version>")
}
}Important: Before using the tracker on Android, you must initialize the Android context in your Application class.
Add the following to your Application class:
import android.app.Application
import com.suprbeta.kuri.analytics.MixPanelAndroidContext
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// Initialize MixPanel Android context BEFORE creating any tracker instances
MixPanelAndroidContext.setUp(this)
}
}Don't forget to register your Application class in AndroidManifest.xml:
<application
android:name=".MyApplication"
...>
</application>No additional setup is required for iOS.
Initialize the tracker with your Mixpanel project token:
val tracker = MixPanelAnalyticsTracker()
// Initialize with your Mixpanel token
tracker.init("your-mixpanel-token")Track simple events:
// Track a simple event without properties
tracker.trackEvent("page_viewed", null)Track events with properties:
// Track an event with additional context
tracker.trackEvent("button_clicked", mapOf(
"button_name" to "submit",
"screen" to "login"
))
// Track a purchase event
tracker.trackEvent("purchase_completed", mapOf(
"item_id" to "SKU-123",
"price" to 29.99,
"currency" to "USD",
"quantity" to 2
))import com.suprbeta.kuri.analytics.MixPanelAnalyticsTracker
class AnalyticsManager {
private val tracker = MixPanelAnalyticsTracker()
suspend fun initialize(token: String) {
tracker.init(token)
}
fun trackUserAction(action: String, metadata: Map<String, Any>? = null) {
tracker.trackEvent(action, metadata)
}
fun trackScreenView(screenName: String) {
tracker.trackEvent("screen_viewed", mapOf(
"screen_name" to screenName,
"timestamp" to System.currentTimeMillis()
))
}
}| Platform | Status |
|---|---|
| Android | Supported |
| iOS | Supported |
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions:
Find this repository useful? ❤️ Follow me for my next creations! 🤩
A Kotlin Multiplatform library for integrating Mixpanel analytics across Android and iOS platforms.
mixpanel-kmp provides a unified, type-safe API for tracking analytics events with Mixpanel across Android and iOS. Built with Kotlin Multiplatform, it allows you to write your analytics tracking logic once and deploy it on both mobile platforms.
Note: This library is a Kotlin Multiplatform wrapper around the native Mixpanel SDKs for Android and iOS. It depends on the official Mixpanel SDK for Android and the Mixpanel SDK for iOS under the hood.
Add the dependency to your build.gradle.kts:
commonMain {
dependencies {
implementation("io.github.itsivag:mixpanel-kmp:<latest-version>")
}
}Important: Before using the tracker on Android, you must initialize the Android context in your Application class.
Add the following to your Application class:
import android.app.Application
import com.suprbeta.kuri.analytics.MixPanelAndroidContext
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// Initialize MixPanel Android context BEFORE creating any tracker instances
MixPanelAndroidContext.setUp(this)
}
}Don't forget to register your Application class in AndroidManifest.xml:
<application
android:name=".MyApplication"
...>
</application>No additional setup is required for iOS.
Initialize the tracker with your Mixpanel project token:
val tracker = MixPanelAnalyticsTracker()
// Initialize with your Mixpanel token
tracker.init("your-mixpanel-token")Track simple events:
// Track a simple event without properties
tracker.trackEvent("page_viewed", null)Track events with properties:
// Track an event with additional context
tracker.trackEvent("button_clicked", mapOf(
"button_name" to "submit",
"screen" to "login"
))
// Track a purchase event
tracker.trackEvent("purchase_completed", mapOf(
"item_id" to "SKU-123",
"price" to 29.99,
"currency" to "USD",
"quantity" to 2
))import com.suprbeta.kuri.analytics.MixPanelAnalyticsTracker
class AnalyticsManager {
private val tracker = MixPanelAnalyticsTracker()
suspend fun initialize(token: String) {
tracker.init(token)
}
fun trackUserAction(action: String, metadata: Map<String, Any>? = null) {
tracker.trackEvent(action, metadata)
}
fun trackScreenView(screenName: String) {
tracker.trackEvent("screen_viewed", mapOf(
"screen_name" to screenName,
"timestamp" to System.currentTimeMillis()
))
}
}| Platform | Status |
|---|---|
| Android | Supported |
| iOS | Supported |
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions:
Find this repository useful? ❤️ Follow me for my next creations! 🤩