Repository navigation
feat!: rename PostHogConfig.apiKey to projectToken - #91
Conversation
Matches posthog-ios 4.0 and posthog-flutter. apiKey stays as a deprecated getter and a deprecated PostHogConfig(apiKey = ...) factory; only copy(apiKey = ...) stops compiling.
|
marandaneto
left a comment
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
|
For clarity, |
Positional calls compile against current posthog-android/core and the upcoming release that deprecates the apiKey parameter name. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
💡 Motivation and Context
Rename
PostHogConfig.apiKeytoprojectToken, so KMP uses the same name as posthog-ios 4.0 and posthog-flutter. The iOS actual already callsPostHogConfig(projectToken:)(#87). Android/JVM still pass the value to posthog-android'sapiKey. Only the KMP public API changes.This ships alongside #89 in the same breaking 0.x release.
PostHogConfig("phc_...")PostHogConfig(projectToken = "phc_...")PostHogConfig(apiKey = "phc_...", ...)Companion.invokewith the same parameters)config.apiKeyReplaceWith("projectToken"))config.copy(apiKey = ...)copy(projectToken = ...)copy(apiKey = ...)overload would clash with the generatedcopyon the JVM (same parameter types), so that call is the one source break.getApiKey()still exists as a deprecated getter. The existingHIDDENconstructor andcopyoverloads stay as they are.Docs follow-up: posthog.com
contents/docs/libraries/kmp/index.mdxstill usesapiKeyat lines 89, 114, 136, 152, 166, 271, 501, 535, 566, 636, and in the config table at line 650. Those need a separate posthog.com PR.💚 How did you test it?
PostHogConfigTest.deprecatedApiKeyAliasesProjectToken. It checks that the deprecated factory builds the same config asprojectTokenand thatapiKeyreads it back../gradlew detekt :posthog-kmp:testAndroid :sample:androidApp:assembleDebug :posthog-kmp:jvmTest :posthog-kmp:jsTest :posthog-kmp:wasmJsBrowserTest :sample:wasmJsBrowserDistribution :posthog-kmp:iosSimulatorArm64Test :posthog-kmp:macosArm64Test, then./gradlew build allTests.PostHogConfig(apiKey = ...)andconfig.apiKey, and no warning for positionalPostHogConfig("phc_...").📝 Checklist
If releasing new changes
pnpm changeto generate a change intent file (written by hand in the same format:.changeset/project-token-rename.md)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Companion.invokefactory over a secondary constructor. A constructor with anapiKeyparameter and the same types would clash with the primary constructor. With the factory, the real constructor still wins resolution for positional andprojectTokencalls.Follow-up once PostHog/posthog-android#835 is released
The Android and JVM actuals pass the token positionally (
PostHog.android.kt:8,PostHog.jvm.kt:16), so they compile against the current pins and the release that deprecatesapiKey, with no warning. After #835 ships:posthog-android(currently 3.66.0) andposthog-core(currently 6.38.0) ingradle/libs.versions.tomlcoreConfig.apiKeytocoreConfig.projectTokenin the JVM prefs file path (PostHog.jvm.kt:41). It's the same trimmed value, so existing prefs files are still found.🤖 Generated with Claude Code