Repository navigation
feat: add an Objective-C setter for the wrapper SDK name and version - #1027
Merged
Merged
Conversation
Kotlin Multiplatform calls posthog-ios through its Objective-C header, so it can't assign the Swift-only `postHogSdkName`/`postHogVersion` globals. With capture v1 dropping `$lib` from event properties, every KMP Apple event would report as posthog-ios. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
turnipdabeets
added a commit
to PostHog/posthog-kmp
that referenced
this pull request
Nov 4, 2026
Capture v1 strips `$lib`/`$lib_version` from event properties and reads them from the PostHog-Sdk-Info header, so the `$lib` stamping in beforeSend no longer reaches PostHog. Set the native SDK name and version before setup instead (PostHog/posthog-ios#1027), drop the stamping, and only install the native beforeSend when the app configures callbacks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 of 15 tasks
turnipdabeets
marked this pull request as ready for review
November 4, 2026 20:32
Contributor
posthog-ios Compliance ReportDate: 2026-11-04T20:45:48.515825+00:00
|
| Test | Status | Duration |
|---|---|---|
| Format Validation.Event Has Required Fields | ✅ | 2919ms |
| Format Validation.Event Has Uuid | ✅ | 2833ms |
| Format Validation.Event Has Lib Properties | ✅ | 2834ms |
| Format Validation.Distinct Id Is String | ✅ | 2926ms |
| Format Validation.Token Is Present | ✅ | 427ms |
| Format Validation.Custom Properties Preserved | ✅ | 2943ms |
| Format Validation.Event Has Timestamp | ✅ | 2951ms |
| Format Validation.Non Utc Event Timestamp Is Converted To Utc | ✅ | 2784ms |
| Retry Behavior.Retries On 503 | ✅ | 11754ms |
| Retry Behavior.Does Not Retry On 400 | ✅ | 4798ms |
| Retry Behavior.Does Not Retry On 401 | ✅ | 4814ms |
| Retry Behavior.Respects Retry After Header | ✅ | 7918ms |
| Retry Behavior.Implements Backoff | ✅ | 21789ms |
| Retry Behavior.Retries On 500 | ✅ | 9272ms |
| Retry Behavior.Retries On 502 | ✅ | 8934ms |
| Retry Behavior.Retries On 504 | ✅ | 9341ms |
| Retry Behavior.Max Retries Respected | ❌ | 21707ms |
| Deduplication.Generates Unique Uuids | ✅ | 2922ms |
| Deduplication.Preserves Uuid On Retry | ✅ | 9233ms |
| Deduplication.Preserves Uuid And Timestamp On Retry | ✅ | 16296ms |
| Deduplication.Preserves Uuid And Timestamp On Batch Retry | ✅ | 7930ms |
| Deduplication.No Duplicate Events In Batch | ✅ | 3038ms |
| Deduplication.Different Events Have Different Uuids | ✅ | 2966ms |
| Compression.Sends Gzip When Enabled | ✅ | 441ms |
| Batch Format.Uses Proper Batch Structure | ✅ | 2859ms |
| Batch Format.Flush With No Events Sends Nothing | ✅ | 352ms |
| Batch Format.Multiple Events Batched Together | ✅ | 3006ms |
| Error Handling.Does Not Retry On 403 | ✅ | 4870ms |
| Error Handling.Does Not Retry On 413 | ✅ | 4838ms |
| Error Handling.Retries On 408 | ✅ | 9310ms |
Failures
retry_behavior.max_retries_respected
Expected 4 requests, got 6
Feature_Flags Tests
✅ 17/17 tests passed
View Details
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ✅ | 2819ms |
| Request Payload.Flags Request Uses V2 Query Param | ✅ | 2833ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ✅ | 2829ms |
| Request Payload.Flags Request Omits Authorization Header | ✅ | 2742ms |
| Request Payload.Token In Flags Body Matches Init | ✅ | 2787ms |
| Request Payload.Groups Round Trip | ✅ | 2734ms |
| Request Payload.Groups Default To Empty Object | ✅ | 3138ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ✅ | 2791ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ✅ | 2864ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ✅ | 2708ms |
| Request Lifecycle.No Flags Request On Init Alone | ✅ | 111ms |
| Request Lifecycle.No Flags Request On Normal Capture | ✅ | 2834ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ✅ | 5489ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ✅ | 2811ms |
| Retry Behavior.Retries Flags On 502 | ✅ | 2963ms |
| Retry Behavior.Retries Flags On 504 | ✅ | 2857ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ✅ | 2964ms |
eli-r-ph
reviewed
Nov 4, 2026
| } | ||
| let request = try #require(server.batchRequests.first) | ||
| #expect(request.value(forHTTPHeaderField: "User-Agent") == "posthog-kmp/1.2.3") | ||
| } |
There was a problem hiding this comment.
Once this meets the capture v1 branch, could the test also check the PostHog-Sdk-Info header? That's the one PostHog reads for the SDK name.
Contributor
Author
There was a problem hiding this comment.
will add this to #938 since this doesnt target that branch
Contributor
Author
ioannisj
approved these changes
Nov 5, 2026
ioannisj
left a comment
Contributor
There was a problem hiding this comment.
🤖 An AI agent wrote this on behalf of @ioannisj.
No findings. I checked the setter against the generated PostHog-Swift.h and the public API snapshot, and it's in the header and stays out of the snapshot, as the description says.
turnipdabeets
added a commit
that referenced
this pull request
Nov 5, 2026
PostHogApi.batch is captureV1 on this branch, so the setSdkName test from #1027 sends through it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 of 18 tasks
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.
Public API change: none. Adds
PostHogSDK.setSdkName(_:version:)behind@_spi(PostHogInternal), next to thepostHogSdkName/postHogVersionglobals it sets.💡 Motivation and Context
Capture v1 (#938) drops
$lib/$lib_versionfrom event properties and reads the SDK name and version from thePostHog-Sdk-Infoheader, built frompostHogSdkName/postHogVersion. Those are Swift globals, so they aren't in the Objective-C header. Kotlin Multiplatform calls posthog-ios through that header, so it can't set them. Today it stamps$libinbeforeSend, and capture v1 strips that out. Without this setter, every KMP Apple event on 4.0 reports asposthog-ios.@objc(setSdkName:version:)is a class method in aPostHogSDKextension. The generatedPostHog-Swift.hincludes it,@_spiincluded, the same wayPostHogSessionManageris already exposed. Swift wrappers (Flutter) keep assigning the globals directly.setup.PostHogContextcaches$libfor person properties the first time it reads it.KMP adopts it in PostHog/posthog-kmp#108.
💚 How did you test it?
PostHogApiTest:PostHogSDKresponds tosetSdkName:version:from the ObjC runtime, and a request sent afterwards hasUser-Agent: posthog-kmp/1.2.3. Dropping the@objcmakes it fail.make test filter=PostHogApiTest: 65 tests pass.make lintpasses (warnings only)./i/v1/analytics/eventsreceivedPostHog-Sdk-Info: posthog-kmp/0.10.0, with no$libin the body.make test,make apiCheck(xcprettyisn't installed locally; the setter is SPI, so the public API snapshots shouldn't change), and the Xcode-scheme iOS simulator tests: the test runner hung before connecting on this machine.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file (added to.changeset/v4-major-release.md, where this branch folds 4.0 changes)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Claude Opus 5.5) wrote the setter while preparing KMP for posthog-ios 4.0. Before writing it, I checked that an
@_spi @objcmember still appears in the generated ObjC header, so it could stay wrapper-only instead of becoming public API. The setter targets the 4.0 branch rather than #938 because it only touches the existing globals.🤖 Generated with Claude Code