Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(onboarding): add kotlin multiplatform to sdk setup and onboarding (#83572)

Anna Garcia328025191b96
diff --git a/docs/onboarding/experiments/_snippets/experiment-implementation.tsx b/docs/onboarding/experiments/_snippets/experiment-implementation.tsx
index 4abbe7b05319..375e9dedac92 100644
--- a/docs/onboarding/experiments/_snippets/experiment-implementation.tsx
+++ b/docs/onboarding/experiments/_snippets/experiment-implementation.tsx
@@ -131,6 +131,14 @@ export const ExperimentImplementationSnippet = memo(
// It's a good idea to let control variant always be the default behaviour,
// so if something goes wrong with flag evaluation, you don't break your app.
}
+ `,
+ kmp: dedent`
+ if (PostHog.getFeatureFlag("your-experiment-feature-flag") == "test") {
+ // do something
+ } else {
+ // It's a good idea to let control variant always be the default behaviour,
+ // so if something goes wrong with flag evaluation, you don't break your app.
+ }
`,
}
@@ -146,6 +154,7 @@ export const ExperimentImplementationSnippet = memo(
android: 'kotlin',
ios: 'swift',
flutter: 'dart',
+ kmp: 'kotlin',
}
return (
diff --git a/docs/onboarding/experiments/index.ts b/docs/onboarding/experiments/index.ts
index 2bd298964310..314676515d14 100644
--- a/docs/onboarding/experiments/index.ts
+++ b/docs/onboarding/experiments/index.ts
@@ -11,6 +11,7 @@ export { FlutterInstallation } from './flutter'
export { FramerInstallation } from './framer'
export { GoInstallation } from './go'
export { IOSInstallation } from './ios'
+export { KMPInstallation } from './kmp'
export { WebInstallation } from './web'
export { LaravelInstallation } from './laravel'
export { NextJSInstallation } from './nextjs'
diff --git a/docs/onboarding/experiments/kmp.tsx b/docs/onboarding/experiments/kmp.tsx
new file mode 100644
index 000000000000..556e1179bda5
--- /dev/null
+++ b/docs/onboarding/experiments/kmp.tsx
@@ -0,0 +1,45 @@
+import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
+
+import { getKMPSteps as getKMPStepsPA } from '../product-analytics/kmp'
+import { StepDefinition } from '../steps'
+
+export const getKMPSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
+ const { Markdown, dedent, snippets } = ctx
+ const ExperimentImplementation = snippets?.ExperimentImplementationSnippet
+
+ // Get installation steps from product-analytics only
+ const installationSteps = getKMPStepsPA(ctx).filter((step: StepDefinition) => step.title !== 'Send events')
+
+ // Add experiments-specific steps
+ const experimentSteps: StepDefinition[] = [
+ {
+ title: 'Implement your experiment',
+ badge: 'required',
+ content: (
+ <>
+ <Markdown>
+ {dedent`
+ Experiments run on top of our feature flags. You can define which version of your code runs based on the return value of the feature flag:
+ `}
+ </Markdown>
+ {ExperimentImplementation && <ExperimentImplementation language="kmp" />}
+ </>
+ ),
+ },
+ {
+ title: 'Run your experiment',
+ badge: 'required',
+ content: (
+ <Markdown>
+ {dedent`
+ Once you've implemented the feature flag in your code, you'll enable it for a target audience by creating a new experiment in the PostHog dashboard.
+ `}
+ </Markdown>
+ ),
+ },
+ ]
+
+ return [...installationSteps, ...experimentSteps]
+}
+
+export const KMPInstallation = createInstallation(getKMPSteps)
diff --git a/docs/onboarding/feature-flags/index.ts b/docs/onboarding/feature-flags/index.ts
index d6b9ef6d1b42..e37213780113 100644
--- a/docs/onboarding/feature-flags/index.ts
+++ b/docs/onboarding/feature-flags/index.ts
@@ -16,6 +16,7 @@ export { FlutterInstallation } from './flutter'
export { FramerInstallation } from './framer'
export { GoInstallation } from './go'
export { IOSInstallation } from './ios'
+export { KMPInstallation } from './kmp'
export { WebInstallation } from './web'
export { LaravelInstallation } from './laravel'
export { NextJSInstallation } from './nextjs'
diff --git a/docs/onboarding/feature-flags/kmp.tsx b/docs/onboarding/feature-flags/kmp.tsx
new file mode 100644
index 000000000000..f21daf9b4da5
--- /dev/null
+++ b/docs/onboarding/feature-flags/kmp.tsx
@@ -0,0 +1,111 @@
+import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
+
+import { getKMPSteps as getKMPStepsPA } from '../product-analytics/kmp'
+import { StepDefinition } from '../steps'
+
+export const getKMPSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
+ const { CodeBlock, Markdown, dedent } = ctx
+
+ // Get installation steps from product-analytics
+ const installationSteps = getKMPStepsPA(ctx)
+
+ // Add flag-specific steps
+ const flagSteps: StepDefinition[] = [
+ {
+ title: 'Evaluate boolean feature flags',
+ badge: 'required',
+ content: (
+ <>
+ <Markdown>
+ {dedent`
+ Flags are preloaded on setup, so this call is synchronous:
+ `}
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'Kotlin',
+ code: dedent`
+ if (PostHog.isFeatureEnabled("flag-key")) {
+ // Do something differently for this user
+ // Optional: fetch the payload
+ val payload = PostHog.getFeatureFlagResult("flag-key")?.getPayloadAs<Map<String, Any>>()
+ }
+ `,
+ },
+ ]}
+ />
+ </>
+ ),
+ },
+ {
+ title: 'Evaluate multivariate feature flags',
+ badge: 'optional',
+ content: (
+ <>
+ <Markdown>
+ {dedent`
+ For multivariate flags, check which variant the user has been assigned:
+ `}
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'Kotlin',
+ code: dedent`
+ when (PostHog.getFeatureFlag("flag-key")) {
+ "control" -> showOriginalPricing()
+ "variant-key" -> showNewPricing()
+ }
+ `,
+ },
+ ]}
+ />
+ </>
+ ),
+ },
+ {
+ title: 'Reload flags after identifying',
+ badge: 'optional',
+ content: (
+ <>
+ <Markdown>
+ {dedent`
+ Flags are fetched on setup and cached. If a user's properties change – for example, after \`identify\` – reload them so they reflect the latest state:
+ `}
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'Kotlin',
+ code: dedent`
+ PostHog.reloadFeatureFlags {
+ // flags are now up to date
+ }
+ `,
+ },
+ ]}
+ />
+ </>
+ ),
+ },
+ {
+ title: 'Running experiments',
+ badge: 'optional',
+ content: (
+ <Markdown>
+ {dedent`
+ Experiments run on top of our feature flags. Once you've implemented the flag in your code, you run an experiment by creating a new experiment in the PostHog dashboard.
+ `}
+ </Markdown>
+ ),
+ },
+ ]
+
+ return [...installationSteps, ...flagSteps]
+}
+
+export const KMPInstallation = createInstallation(getKMPSteps)
diff --git a/docs/onboarding/product-analytics/index.ts b/docs/onboarding/product-analytics/index.ts
index 448f3906e1a3..ed1f30693898 100644
--- a/docs/onboarding/product-analytics/index.ts
+++ b/docs/onboarding/product-analytics/index.ts
@@ -25,6 +25,7 @@ export { GoInstallation } from './go'
export { GoogleTagManagerInstallation } from './google-tag-manager'
export { HeliconeInstallation } from './helicone'
export { IOSInstallation } from './ios'
+export { KMPInstallation } from './kmp'
export { LangfuseInstallation } from './langfuse'
export { LaravelInstallation } from './laravel'
export { MoEngageInstallation } from './moengage'
diff --git a/docs/onboarding/product-analytics/kmp.tsx b/docs/onboarding/product-analytics/kmp.tsx
new file mode 100644
index 000000000000..477480eb5359
--- /dev/null
+++ b/docs/onboarding/product-analytics/kmp.tsx
@@ -0,0 +1,224 @@
+import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
+
+import { StepDefinition } from '../steps'
+
+export const getKMPSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
+ const { CodeBlock, Markdown, Tab, dedent } = ctx
+
+ return [
+ {
+ title: 'Install the dependency',
+ badge: 'required',
+ content: (
+ <>
+ <Markdown>Add the PostHog KMP SDK to your shared module's `commonMain` source set:</Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'shared/build.gradle.kts',
+ code: dedent`
+ kotlin {
+ sourceSets {
+ commonMain.dependencies {
+ implementation("com.posthog:posthog-kmp:0.+")
+ }
+ }
+ }
+ `,
+ },
+ ]}
+ />
+ <Markdown>
+ `0.+` resolves to the latest `0.x` release. The SDK is a pre-release, so the API can change
+ between minor versions – pin an exact version from [Maven
+ Central](https://central.sonatype.com/artifact/com.posthog/posthog-kmp) if you would rather
+ upgrade deliberately. Kotlin/Wasm support requires `0.2.0` or higher.
+ </Markdown>
+ </>
+ ),
+ },
+ {
+ title: 'Configure PostHog',
+ badge: 'required',
+ content: (
+ <>
+ <Markdown>
+ Call `PostHog.setup()` once, early in your app's lifecycle. The config is shared across every
+ target – only the `PostHogContext` differs per platform.
+ </Markdown>
+ <Tab.Group tabs={['Android', 'iOS', 'Web', 'JVM']}>
+ <Tab.Panels>
+ <Tab.Panel>
+ <Markdown>
+ Android needs the `Application` instance, so set PostHog up from your `Application`
+ class – not from an Activity, whose `onCreate` re-runs on every recreation (for
+ example, on rotation):
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'MyApplication.kt',
+ code: dedent`
+ import android.app.Application
+ import com.posthog.kmp.PostHog
+ import com.posthog.kmp.PostHogConfig
+ import com.posthog.kmp.PostHogContext
+
+ class MyApplication : Application() {
+ override fun onCreate() {
+ super.onCreate()
+
+ PostHog.setup(
+ config = PostHogConfig(
+ apiKey = "<ph_project_token>",
+ host = "<ph_client_api_host>",
+ ),
+ context = PostHogContext(this),
+ )
+ }
+ }
+ `,
+ },
+ ]}
+ />
+ <Markdown>Register the class in your `AndroidManifest.xml`:</Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'xml',
+ file: 'android/src/main/AndroidManifest.xml',
+ code: dedent`
+ <application android:name=".MyApplication" ...>
+ `,
+ },
+ ]}
+ />
+ </Tab.Panel>
+ <Tab.Panel>
+ <Markdown>On iOS, use the no-argument `PostHogContext()`:</Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'MainViewController.kt',
+ code: dedent`
+ import com.posthog.kmp.PostHog
+ import com.posthog.kmp.PostHogConfig
+ import com.posthog.kmp.PostHogContext
+
+ fun MainViewController() = ComposeUIViewController {
+ LaunchedEffect(Unit) {
+ PostHog.setup(
+ config = PostHogConfig(
+ apiKey = "<ph_project_token>",
+ host = "<ph_client_api_host>",
+ ),
+ context = PostHogContext(),
+ )
+ }
+ App()
+ }
+ `,
+ },
+ ]}
+ />
+ </Tab.Panel>
+ <Tab.Panel>
+ <Markdown>
+ On the web (Kotlin/JS and Kotlin/Wasm), use the no-argument `PostHogContext()`:
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'main.kt',
+ code: dedent`
+ import com.posthog.kmp.PostHog
+ import com.posthog.kmp.PostHogConfig
+ import com.posthog.kmp.PostHogContext
+
+ fun main() {
+ PostHog.setup(
+ config = PostHogConfig(
+ apiKey = "<ph_project_token>",
+ host = "<ph_client_api_host>",
+ ),
+ context = PostHogContext(),
+ )
+ }
+ `,
+ },
+ ]}
+ />
+ </Tab.Panel>
+ <Tab.Panel>
+ <Markdown>
+ On the JVM – for example, a Compose Multiplatform desktop app – use the no-argument
+ `PostHogContext()`:
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'main.kt',
+ code: dedent`
+ import com.posthog.kmp.PostHog
+ import com.posthog.kmp.PostHogConfig
+ import com.posthog.kmp.PostHogContext
+
+ fun main() = application {
+ PostHog.setup(
+ config = PostHogConfig(
+ apiKey = "<ph_project_token>",
+ host = "<ph_client_api_host>",
+ ),
+ context = PostHogContext(),
+ )
+ // ...
+ }
+ `,
+ },
+ ]}
+ />
+ </Tab.Panel>
+ </Tab.Panels>
+ </Tab.Group>
+ </>
+ ),
+ },
+ {
+ title: 'Send events',
+ badge: 'recommended',
+ content: (
+ <>
+ <Markdown>
+ Once installed, PostHog automatically captures app lifecycle events on Android and iOS. Send an
+ event manually from shared code to test your integration:
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'Kotlin',
+ code: dedent`
+ import com.posthog.kmp.PostHog
+
+ PostHog.capture(
+ event = "button_clicked",
+ properties = mapOf(
+ "button_name" to "signup"
+ )
+ )
+ `,
+ },
+ ]}
+ />
+ </>
+ ),
+ },
+ ]
+}
+
+export const KMPInstallation = createInstallation(getKMPSteps)
diff --git a/docs/onboarding/session-replay/index.ts b/docs/onboarding/session-replay/index.ts
index e2f3e1764180..1bbf2c7dcd90 100644
--- a/docs/onboarding/session-replay/index.ts
+++ b/docs/onboarding/session-replay/index.ts
@@ -9,6 +9,7 @@ export { BubbleInstallation } from './bubble'
export { FlutterInstallation } from './flutter'
export { FramerInstallation } from './framer'
export { IOSInstallation } from './ios'
+export { KMPInstallation } from './kmp'
export { WebInstallation } from './web'
export { NextJSInstallation } from './nextjs'
export { NuxtInstallation } from './nuxt'
diff --git a/docs/onboarding/session-replay/kmp.tsx b/docs/onboarding/session-replay/kmp.tsx
new file mode 100644
index 000000000000..20783ebab357
--- /dev/null
+++ b/docs/onboarding/session-replay/kmp.tsx
@@ -0,0 +1,173 @@
+import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
+
+import { StepDefinition } from '../steps'
+
+export const getKMPSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
+ const { CodeBlock, Markdown, CalloutBox, Tab, dedent, snippets } = ctx
+ const SessionReplayFinalSteps = snippets?.SessionReplayFinalSteps
+
+ return [
+ {
+ title: 'Install the dependency',
+ badge: 'required',
+ content: (
+ <>
+ <Markdown>Add the PostHog KMP SDK to your shared module's `commonMain` source set:</Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'shared/build.gradle.kts',
+ code: dedent`
+ kotlin {
+ sourceSets {
+ commonMain.dependencies {
+ implementation("com.posthog:posthog-kmp:0.+")
+ }
+ }
+ }
+ `,
+ },
+ ]}
+ />
+ <Markdown>
+ `0.+` resolves to the latest `0.x` release. The SDK is a pre-release, so the API can change
+ between minor versions – pin an exact version from [Maven
+ Central](https://central.sonatype.com/artifact/com.posthog/posthog-kmp) if you would rather
+ upgrade deliberately.
+ </Markdown>
+ <CalloutBox type="fyi" title="Supported targets">
+ <Markdown>
+ Session replay is captured on Android, iOS and the web. It is ignored on the JVM (desktop)
+ target.
+ </Markdown>
+ </CalloutBox>
+ </>
+ ),
+ },
+ {
+ title: 'Enable session recordings in project settings',
+ badge: 'required',
+ content: (
+ <>
+ <Markdown>
+ Go to your PostHog [Project Settings](https://us.posthog.com/settings/project-replay) and enable
+ **Record user sessions**. Session recordings will not work without this setting enabled.
+ </Markdown>
+ </>
+ ),
+ },
+ {
+ title: 'Configure PostHog with session replay',
+ badge: 'required',
+ content: (
+ <>
+ <Markdown>
+ Pass a `SessionRecordingConfig` to `PostHogConfig` from shared code. Here are all the available
+ options:
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'Kotlin',
+ code: dedent`
+ import com.posthog.kmp.PostHog
+ import com.posthog.kmp.PostHogConfig
+ import com.posthog.kmp.PostHogContext
+ import com.posthog.kmp.SessionRecordingConfig
+
+ val config = PostHogConfig(
+ apiKey = "<ph_project_token>",
+ host = "<ph_client_api_host>",
+
+ // Enable session recording. Requires enabling in your project settings as well.
+ sessionRecording = SessionRecordingConfig(
+ enabled = true,
+
+ // Whether text input values are masked. Default is true.
+ maskAllTextInputs = true,
+
+ // Whether images are masked. Default is true.
+ maskAllImages = true,
+
+ // Whether network requests are included in the recording. Default is true.
+ captureNetworkTelemetry = true,
+
+ // Capture console and system logs (iOS and web). Default is false.
+ captureLogs = false,
+
+ // Whether replays are created using high quality screenshots instead of
+ // wireframes (experimental, Android and iOS). Default is false.
+ // Screenshots may contain sensitive information, so use with caution.
+ screenshot = false,
+
+ // Capture Android logcat output (Android only). Default is true.
+ captureLogcat = true,
+
+ // Touch event debounce delay in milliseconds (Android only). Default is 1000.
+ debouncerDelayMs = 1000L,
+ ),
+ )
+ `,
+ },
+ ]}
+ />
+ <Markdown>
+ Pass that config to `PostHog.setup()`. Android needs the `Application` instance, so it takes
+ `PostHogContext(application)` – every other target takes the no-argument `PostHogContext()`.
+ </Markdown>
+ <Tab.Group tabs={['Android', 'iOS and web']}>
+ <Tab.Panels>
+ <Tab.Panel>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'MyApplication.kt',
+ code: dedent`
+ import android.app.Application
+
+ class MyApplication : Application() {
+ override fun onCreate() {
+ super.onCreate()
+
+ PostHog.setup(config = config, context = PostHogContext(this))
+ }
+ }
+ `,
+ },
+ ]}
+ />
+ </Tab.Panel>
+ <Tab.Panel>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'Kotlin',
+ code: dedent`
+ PostHog.setup(config = config, context = PostHogContext())
+ `,
+ },
+ ]}
+ />
+ </Tab.Panel>
+ </Tab.Panels>
+ </Tab.Group>
+ <Markdown>
+ For more configuration options, see the [Kotlin Multiplatform session replay
+ docs](https://posthog.com/docs/libraries/kmp#session-replay).
+ </Markdown>
+ </>
+ ),
+ },
+ {
+ title: 'Watch session recordings',
+ badge: 'recommended',
+ content: <>{SessionReplayFinalSteps && <SessionReplayFinalSteps />}</>,
+ },
+ ]
+}
+
+export const KMPInstallation = createInstallation(getKMPSteps)
diff --git a/docs/onboarding/web-analytics/index.ts b/docs/onboarding/web-analytics/index.ts
index f563422c9790..44958f6c1d5b 100644
--- a/docs/onboarding/web-analytics/index.ts
+++ b/docs/onboarding/web-analytics/index.ts
@@ -12,6 +12,7 @@ export { FlutterInstallation } from './flutter'
export { FramerInstallation } from './framer'
export { GoogleTagManagerInstallation } from './google-tag-manager'
export { IOSInstallation } from './ios'
+export { KMPInstallation } from './kmp'
export { WebInstallation } from './web'
export { NextJSInstallation } from './nextjs'
export { NuxtInstallation } from './nuxt'
diff --git a/docs/onboarding/web-analytics/kmp.tsx b/docs/onboarding/web-analytics/kmp.tsx
new file mode 100644
index 000000000000..a4a7c0288d28
--- /dev/null
+++ b/docs/onboarding/web-analytics/kmp.tsx
@@ -0,0 +1,68 @@
+import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
+
+import { getKMPSteps as getKMPStepsPA } from '../product-analytics/kmp'
+import { StepDefinition } from '../steps'
+
+export const getKMPSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
+ const { Markdown, CodeBlock, dedent, snippets } = ctx
+ const MobileFinalSteps = snippets?.MobileFinalSteps
+
+ // Get installation steps from product-analytics
+ const paSteps = getKMPStepsPA(ctx)
+
+ // Replace the "Send events" step with web analytics specific content
+ return paSteps.map((step) => {
+ if (step.title === 'Send events') {
+ return {
+ title: 'Track screen views',
+ badge: 'recommended' as const,
+ content: (
+ <>
+ {MobileFinalSteps && <MobileFinalSteps />}
+ <Markdown>
+ Screen views are off by default. Set `captureScreenViews = true` to capture them
+ automatically – screen views on Android and iOS, pageviews on the web:
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'Kotlin',
+ code: dedent`
+ PostHogConfig(
+ apiKey = "<ph_project_token>",
+ host = "<ph_client_api_host>",
+ captureScreenViews = true,
+ )
+ `,
+ },
+ ]}
+ />
+ <Markdown>You can also capture a screen view yourself from shared code:</Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'kotlin',
+ file: 'Kotlin',
+ code: dedent`
+ import com.posthog.kmp.PostHog
+
+ PostHog.screen(
+ screenName = "Dashboard",
+ properties = mapOf(
+ "background" to "blue"
+ )
+ )
+ `,
+ },
+ ]}
+ />
+ </>
+ ),
+ }
+ }
+ return step
+ })
+}
+
+export const KMPInstallation = createInstallation(getKMPSteps)
diff --git a/frontend/src/scenes/onboarding/legacy/sdks/experiments/ExperimentsSDKInstructions.tsx b/frontend/src/scenes/onboarding/legacy/sdks/experiments/ExperimentsSDKInstructions.tsx
index c83286042e85..87d337465852 100644
--- a/frontend/src/scenes/onboarding/legacy/sdks/experiments/ExperimentsSDKInstructions.tsx
+++ b/frontend/src/scenes/onboarding/legacy/sdks/experiments/ExperimentsSDKInstructions.tsx
@@ -9,6 +9,7 @@ import {
FramerInstallation,
GoInstallation,
IOSInstallation,
+ KMPInstallation,
WebInstallation,
LaravelInstallation,
NextJSInstallation,
@@ -171,6 +172,12 @@ const ExperimentsFlutterInstructionsWrapper = withMobileReplay({
onboardingContext: 'experiments-onboarding',
snippets: MOBILE_SNIPPETS,
})
+const ExperimentsKMPInstructionsWrapper = withMobileReplay({
+ Installation: KMPInstallation,
+ sdkKey: SDKKey.KMP,
+ onboardingContext: 'experiments-onboarding',
+ snippets: MOBILE_SNIPPETS,
+})
const ExperimentsRNInstructionsWrapper = withMobileReplay({
Installation: ReactNativeInstallation,
sdkKey: SDKKey.REACT_NATIVE,
@@ -260,6 +267,7 @@ export const ExperimentsSDKInstructions: SDKInstructionsMap = {
[SDKKey.FRAMER]: ExperimentsFramerInstructionsWrapper,
[SDKKey.GO]: ExperimentsGoInstructionsWrapper,
[SDKKey.IOS]: ExperimentsIOSInstructionsWrapper,
+ [SDKKey.KMP]: ExperimentsKMPInstructionsWrapper,
[SDKKey.LARAVEL]: ExperimentsLaravelInstructionsWrapper,
[SDKKey.NEXT_JS]: ExperimentsNextJSInstructionsWrapper,
[SDKKey.NODE_JS]: ExperimentsNodeInstructionsWrapper,
diff --git a/frontend/src/scenes/onboarding/legacy/sdks/feature-flags/FeatureFlagsSDKInstructions.tsx b/frontend/src/scenes/onboarding/legacy/sdks/feature-flags/FeatureFlagsSDKInstructions.tsx
index a5de294d231a..0a5545db3aad 100644
--- a/frontend/src/scenes/onboarding/legacy/sdks/feature-flags/FeatureFlagsSDKInstructions.tsx
+++ b/frontend/src/scenes/onboarding/legacy/sdks/feature-flags/FeatureFlagsSDKInstructions.tsx
@@ -11,6 +11,7 @@ import {
FramerInstallation,
GoInstallation,
IOSInstallation,
+ KMPInstallation,
WebInstallation,
LaravelInstallation,
MultivariateFlagSnippet,
@@ -232,6 +233,12 @@ const FeatureFlagsFlutterInstructionsWrapper = withMobileReplay({
onboardingContext: 'flags-onboarding',
snippets: FLAG_IMPLEMENTATION_SNIPPETS,
})
+const FeatureFlagsKMPInstructionsWrapper = withMobileReplay({
+ Installation: KMPInstallation,
+ sdkKey: SDKKey.KMP,
+ onboardingContext: 'flags-onboarding',
+ snippets: FLAG_IMPLEMENTATION_SNIPPETS,
+})
const FeatureFlagsRNInstructionsWrapper = withMobileReplay({
Installation: ReactNativeInstallation,
sdkKey: SDKKey.REACT_NATIVE,
@@ -279,6 +286,7 @@ export const FeatureFlagsSDKInstructions: SDKInstructionsMap = {
[SDKKey.FRAMER]: FeatureFlagsFramerInstructionsWrapper,
[SDKKey.GO]: FeatureFlagsGoInstructionsWrapper,
[SDKKey.IOS]: FeatureFlagsIOSInstructionsWrapper,
+ [SDKKey.KMP]: FeatureFlagsKMPInstructionsWrapper,
[SDKKey.LARAVEL]: FeatureFlagsLaravelInstructionsWrapper,
[SDKKey.NEXT_JS]: FeatureFlagsNextJSInstructionsWrapper,
[SDKKey.NODE_JS]: FeatureFlagsNodeInstructionsWrapper,
diff --git a/frontend/src/scenes/onboarding/legacy/sdks/kmpSDKInstructions.test.ts b/frontend/src/scenes/onboarding/legacy/sdks/kmpSDKInstructions.test.ts
new file mode 100644
index 000000000000..f49e68731a9a
--- /dev/null
+++ b/frontend/src/scenes/onboarding/legacy/sdks/kmpSDKInstructions.test.ts
@@ -0,0 +1,37 @@
+import { SDK_CONFIGS } from 'scenes/settings/environment/SDKSetupInstructions'
+
+import { SDKInstructionsMap, SDKKey } from '~/types'
+
+import { ExperimentsSDKInstructions } from './experiments/ExperimentsSDKInstructions'
+import { FeatureFlagsSDKInstructions } from './feature-flags/FeatureFlagsSDKInstructions'
+import { getAvailableSDKs } from './getAvailableSDKs'
+import { ProductAnalyticsSDKInstructions } from './product-analytics/ProductAnalyticsSDKInstructions'
+import { SessionReplaySDKInstructions } from './session-replay/SessionReplaySDKInstructions'
+import { WebAnalyticsSDKInstructions } from './web-analytics/WebAnalyticsSDKInstructions'
+
+const KMP_DOCS_LINK = 'https://posthog.com/docs/libraries/kmp'
+
+describe('Kotlin Multiplatform onboarding', () => {
+ const productsSupportingKMP: Array<[string, SDKInstructionsMap]> = [
+ ['product analytics', ProductAnalyticsSDKInstructions],
+ ['session replay', SessionReplaySDKInstructions],
+ ['feature flags', FeatureFlagsSDKInstructions],
+ ['experiments', ExperimentsSDKInstructions],
+ ['web analytics', WebAnalyticsSDKInstructions],
+ ]
+
+ it.each(productsSupportingKMP)('makes KMP selectable in %s onboarding', (_product, instructions) => {
+ const sdk = getAvailableSDKs(instructions, {}, {}).find(({ key }) => key === SDKKey.KMP)
+
+ expect(instructions[SDKKey.KMP]).not.toBeUndefined()
+ expect(sdk).toMatchObject({ key: SDKKey.KMP, docsLink: KMP_DOCS_LINK })
+ })
+
+ it('lists KMP as a mobile SDK in the SDK setup picker', () => {
+ expect(SDK_CONFIGS[SDKKey.KMP]).toMatchObject({
+ name: 'Kotlin Multiplatform',
+ docsLink: KMP_DOCS_LINK,
+ category: 'mobile',
+ })
+ })
+})
diff --git a/frontend/src/scenes/onboarding/legacy/sdks/product-analytics/ProductAnalyticsSDKInstructions.tsx b/frontend/src/scenes/onboarding/legacy/sdks/product-analytics/ProductAnalyticsSDKInstructions.tsx
index 824f33f64952..3b89a1218446 100644
--- a/frontend/src/scenes/onboarding/legacy/sdks/product-analytics/ProductAnalyticsSDKInstructions.tsx
+++ b/frontend/src/scenes/onboarding/legacy/sdks/product-analytics/ProductAnalyticsSDKInstructions.tsx
@@ -13,6 +13,7 @@ import {
GoogleTagManagerInstallation,
HeliconeInstallation,
IOSInstallation,
+ KMPInstallation,
LangfuseInstallation,
LaravelInstallation,
MoEngageInstallation,
@@ -77,6 +78,11 @@ const ProductAnalyticsFlutterInstructionsWrapper = withMobileReplay({
sdkKey: SDKKey.FLUTTER,
onboardingContext: 'product-analytics-onboarding',
})
+const ProductAnalyticsKMPInstructionsWrapper = withMobileReplay({
+ Installation: KMPInstallation,
+ sdkKey: SDKKey.KMP,
+ onboardingContext: 'product-analytics-onboarding',
+})
const ProductAnalyticsRNInstructionsWrapper = withMobileReplay({
Installation: ReactNativeInstallation,
sdkKey: SDKKey.REACT_NATIVE,
@@ -233,6 +239,7 @@ export const ProductAnalyticsSDKInstructions: SDKInstructionsMap = {
[SDKKey.GOOGLE_TAG_MANAGER]: ProductAnalyticsGoogleTagManagerInstructionsWrapper,
[SDKKey.HELICONE]: ProductAnalyticsHeliconeInstructionsWrapper,
[SDKKey.IOS]: ProductAnalyticsIOSInstructionsWrapper,
+ [SDKKey.KMP]: ProductAnalyticsKMPInstructionsWrapper,
[SDKKey.LANGFUSE]: ProductAnalyticsLangfuseInstructionsWrapper,
[SDKKey.LARAVEL]: ProductAnalyticsLaravelInstructionsWrapper,
[SDKKey.MOENGAGE]: ProductAnalyticsMoEngageInstructionsWrapper,
diff --git a/frontend/src/scenes/onboarding/legacy/sdks/session-replay/AdvertiseMobileReplay.tsx b/frontend/src/scenes/onboarding/legacy/sdks/session-replay/AdvertiseMobileReplay.tsx
index d4147d37926a..54f15fc8ec42 100644
--- a/frontend/src/scenes/onboarding/legacy/sdks/session-replay/AdvertiseMobileReplay.tsx
+++ b/frontend/src/scenes/onboarding/legacy/sdks/session-replay/AdvertiseMobileReplay.tsx
@@ -32,6 +32,9 @@ export function AdvertiseMobileReplay({
case SDKKey.FLUTTER:
platform = 'Flutter'
break
+ case SDKKey.KMP:
+ platform = 'Kotlin Multiplatform'
+ break
}
const dataAttrPlatform = platform.toLowerCase().replace(/\s+/g, '-')
diff --git a/frontend/src/scenes/onboarding/legacy/sdks/session-replay/SessionReplaySDKInstructions.tsx b/frontend/src/scenes/onboarding/legacy/sdks/session-replay/SessionReplaySDKInstructions.tsx
index 5a0d83e62902..3f466321a453 100644
--- a/frontend/src/scenes/onboarding/legacy/sdks/session-replay/SessionReplaySDKInstructions.tsx
+++ b/frontend/src/scenes/onboarding/legacy/sdks/session-replay/SessionReplaySDKInstructions.tsx
@@ -6,6 +6,7 @@ import {
FlutterInstallation,
FramerInstallation,
IOSInstallation,
+ KMPInstallation,
NextJSInstallation,
NuxtInstallation,
ReactInstallation,
@@ -115,6 +116,10 @@ const SessionReplayFlutterInstructionsWrapper = withOnboardingDocsWrapper({
Installation: FlutterInstallation,
snippets: SNIPPETS,
})
+const SessionReplayKMPInstructionsWrapper = withOnboardingDocsWrapper({
+ Installation: KMPInstallation,
+ snippets: SNIPPETS,
+})
const SessionReplayRNInstructionsWrapper = withOnboardingDocsWrapper({
Installation: ReactNativeInstallation,
snippets: SNIPPETS,
@@ -141,4 +146,5 @@ export const SessionReplaySDKInstructions: SDKInstructionsMap = {
[SDKKey.ANDROID]: SessionReplayAndroidInstructionsWrapper,
[SDKKey.REACT_NATIVE]: SessionReplayRNInstructionsWrapper,
[SDKKey.FLUTTER]: SessionReplayFlutterInstructionsWrapper,
+ [SDKKey.KMP]: SessionReplayKMPInstructionsWrapper,
}
diff --git a/frontend/src/scenes/onboarding/legacy/sdks/web-analytics/WebAnalyticsSDKInstructions.tsx b/frontend/src/scenes/onboarding/legacy/sdks/web-analytics/WebAnalyticsSDKInstructions.tsx
index 81b4992a9170..fdcb68edb752 100644
--- a/frontend/src/scenes/onboarding/legacy/sdks/web-analytics/WebAnalyticsSDKInstructions.tsx
+++ b/frontend/src/scenes/onboarding/legacy/sdks/web-analytics/WebAnalyticsSDKInstructions.tsx
@@ -8,6 +8,7 @@ import {
FramerInstallation,
GoogleTagManagerInstallation,
IOSInstallation,
+ KMPInstallation,
MobileFinalSteps,
NextJSInstallation,
NuxtInstallation,
@@ -144,6 +145,10 @@ const WebAnalyticsFlutterInstructionsWrapper = withOnboardingDocsWrapper({
Installation: FlutterInstallation,
snippets: MOBILE_SNIPPETS,
})
+const WebAnalyticsKMPInstructionsWrapper = withOnboardingDocsWrapper({
+ Installation: KMPInstallation,
+ snippets: MOBILE_SNIPPETS,
+})
const WebAnalyticsRNInstructionsWrapper = withOnboardingDocsWrapper({
Installation: ReactNativeInstallation,
snippets: MOBILE_SNIPPETS,
@@ -173,5 +178,6 @@ export const WebAnalyticsSDKInstructions: SDKInstructionsMap = {
[SDKKey.ANDROID]: WebAnalyticsAndroidInstructionsWrapper,
[SDKKey.FLUTTER]: WebAnalyticsFlutterInstructionsWrapper,
[SDKKey.IOS]: WebAnalyticsIOSInstructionsWrapper,
+ [SDKKey.KMP]: WebAnalyticsKMPInstructionsWrapper,
[SDKKey.REACT_NATIVE]: WebAnalyticsRNInstructionsWrapper,
}
diff --git a/frontend/src/scenes/settings/environment/SDKSetupInstructions.tsx b/frontend/src/scenes/settings/environment/SDKSetupInstructions.tsx
index 5beb942e1efc..6e506a079035 100644
--- a/frontend/src/scenes/settings/environment/SDKSetupInstructions.tsx
+++ b/frontend/src/scenes/settings/environment/SDKSetupInstructions.tsx
@@ -16,6 +16,7 @@ import {
GoInstallation,
GoogleTagManagerInstallation,
IOSInstallation,
+ KMPInstallation,
LaravelInstallation,
NextJSInstallation,
NodeEventCapture,
@@ -221,6 +222,13 @@ export const SDK_CONFIGS: { [key in SDKKey]?: SDKConfig } = {
docsLink: 'https://posthog.com/docs/libraries/ios',
category: 'mobile',
},
+ [SDKKey.KMP]: {
+ Installation: KMPInstallation,
+ wizardIntegrationName: 'Kotlin Multiplatform',
+ name: 'Kotlin Multiplatform',
+ docsLink: 'https://posthog.com/docs/libraries/kmp',
+ category: 'mobile',
+ },
// Server
[SDKKey.DJANGO]: {
diff --git a/posthog/api/utils.py b/posthog/api/utils.py
index c2c89c5b7de0..13f0708eab87 100644
--- a/posthog/api/utils.py
+++ b/posthog/api/utils.py
@@ -649,7 +649,7 @@ def on_permitted_recording_domain(permitted_domains: list[str], request: HttpReq
# TODO we will match on the app identifier in the origin instead and allow users to auth those
is_authorized_mobile_client: bool = user_agent is not None and any(
keyword in user_agent
- for keyword in ["posthog-android", "posthog-ios", "posthog-react-native", "posthog-flutter"]
+ for keyword in ["posthog-android", "posthog-ios", "posthog-react-native", "posthog-flutter", "posthog-kmp"]
)
return is_authorized_web_client or is_authorized_mobile_client
diff --git a/posthog/models/team/production_event_activation.py b/posthog/models/team/production_event_activation.py
index d89f9995d8ba..49ff724b7d4c 100644
--- a/posthog/models/team/production_event_activation.py
+++ b/posthog/models/team/production_event_activation.py
@@ -144,6 +144,7 @@ MOBILE_SIDE_LIBS: Final[tuple[str, ...]] = (
"posthog-android",
"posthog-flutter",
"posthog-react-native",
+ "posthog-kmp",
)