feat: add projectToken and deprecate apiKey - #835
Open
turnipdabeets wants to merge 1 commit into
Open
turnipdabeets wants to merge 1 commit into
turnipdabeets wants to merge 1 commit into
Conversation
Contributor
|
[Medium risk] Renames apiKey parameter to projectToken across SDK configuration. The PR appears safe to merge within its explicitly acknowledged compatibility limits. Reviews (1) · Last reviewed commit: "feat: add projectToken and deprecate api..." |
Contributor
posthog-android Compliance ReportDate: 2026-10-03 00:00:04 UTC ✅ All Tests Passed!46/46 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Contributor
Author
|
@marandaneto looks like this didn't make it to a few PRs. OK to continue? It seems like parity is useful. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Add
projectTokentoPostHogConfig(core and server) andPostHogAndroidConfig, and deprecateapiKey. This is the Android part of the cross-SDK rename: posthog-ios #573, posthog-flutter #374, posthog-dotnet #183, posthog-kmp #91.This is a minor release, not a breaking one. The first constructor parameter is renamed
apiKey→projectToken. Parameter names are not part of JVM signatures, so the constructors and existing bytecode are unchanged.PostHogAndroidConfig("phc_...")/new PostHogAndroidConfig("phc_...")PostHogAndroidConfig(projectToken = "phc_...")PostHogAndroidConfig(apiKey = "phc_...", ...)Companion.invokewith the same parameters)config.apiKey/getApiKey()ReplaceWith("projectToken"))PostHogConfig.builder("phc_...")(server)super(apiKey = ...)projectToken =or a positional argumentThe same rows apply to core
com.posthog.PostHogConfigand servercom.posthog.server.PostHogConfig.@JvmSynthetic, so Java callers never see them. Java callers never had named arguments anyway.builder(apiKey)/Builder(apiKey)parameter names stay the same. Renaming them would break Kotlin named calls such asbuilder(apiKey = ...), and a deprecated overload would clash with the new one.api_key,token) still use the same value, so stored queues and preferences carry over.External callers checked (origin/main):
PostHogAndroidConfig(projectToken, host)is positional. No change needed.PostHogAndroidConfig(apiKey, host)is positional. No change needed.PostHogAndroidConfig(apiKey = ...)andcom.posthog.PostHogConfig(apiKey = ...)are named. Both still compile, with a deprecation warning, and switch toprojectToken =on the next bump.Docs follow-up: posthog.com still uses
apiKey =incontents/docs/libraries/android/index.mdx(lines 58, 181, 217, 269, 365, 380) andcontents/docs/integrate/_snippets/install-android.mdx(line 43). Those need a separate posthog.com PR.💚 How did you test it?
deprecated apiKey factory and getter alias projectToken). Each test checks thatapiKey =trims intoprojectToken, thatapiKeyreads it back, and that the other named arguments are passed through. Existing tests now useprojectToken../gradlew build :posthog-android-gradle-plugin:build --continuepassed: spotlessCheck, apiCheck, lint, and unit tests (posthog 1013, posthog-server 568, posthog-android 1506 with 6 skipped, surveys-compose 75; 0 failures). The only failure wasuploadPostHogProguardMappingsReleasein the sample app, because there are no PostHog CLI credentials locally.make testSurveyUI(49 passed), sampleassembleDebug, Java and Spring sample builds,checkReleasewith no lockfile diff, andsdk_compliance_adaptercompile all passed.-Werrorand then removed it. It showed deprecation warnings only forapiKey =and.apiKey. Positional andprojectToken =calls had no warnings.class X : PostHogAndroidConfig(apiKey = ...)failed to compile, as expected..apidiff is additive only:getProjectToken()on core and server, plus the syntheticCompanion.invokeentries (and a newPostHogAndroidConfig.Companion).getApiKey()and all<init>signatures are unchanged.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file (written by hand:.changeset/project-token-rename.md)🤖 Generated with Claude Code