Kotlin Multiplatform Product Analytics installation
- 1
Install the dependency
RequiredAdd the PostHog KMP SDK to your shared module's
commonMainsource set:shared/build.gradle.kts0.+resolves to the latest0.xrelease. The SDK is a pre-release, so the API can change between minor versions – pin an exact version from Maven Central if you would rather upgrade deliberately. Kotlin/Wasm support requires0.2.0or higher. - 2
Configure PostHog
RequiredCall
PostHog.setup()once, early in your app's lifecycle. The config is shared across every target – only thePostHogContextdiffers per platform.Android needs the
Applicationinstance, so set PostHog up from yourApplicationclass – not from an Activity, whoseonCreatere-runs on every recreation (for example, on rotation):MyApplication.ktRegister the class in your
AndroidManifest.xml:android/src/main/AndroidManifest.xmlOn iOS, use the no-argument
PostHogContext():MainViewController.ktOn the web (Kotlin/JS and Kotlin/Wasm), use the no-argument
PostHogContext():main.ktOn the JVM – for example, a Compose Multiplatform desktop app – use the no-argument
PostHogContext():main.kt - 3
Send events
RecommendedOnce installed, PostHog automatically captures app lifecycle events on Android and iOS. Send an event manually from shared code to test your integration:
Kotlin - 4
Next steps
RecommendedNow that you're capturing events, continue with the resources below to learn what else Product Analytics enables within the PostHog platform.
Resource Description Capturing events Learn how to capture custom events beyond autocapture Identifying users Associate events with specific users Creating insights Build trends, funnels, and retention charts Group analytics Track events at the company or account level