Migrate the iOS SDK from 3.x.x to 4.0.0
The iOS SDK 4.x.x sends analytics and AI events to the capture v1 endpoints, /i/v1/analytics/events and /i/v1/ai/events.
On posthog.com, use the copy page button at the top right to work through this with your agents.
You don't need to make every change on the day you upgrade your SDK. Required changes fall in these categories:
- Before you upgrade: These are changes you should make before you upgrade your SDK to posthog-ios 4.x.x.
- During your upgrade: These are changes that you need to make in the same PR that upgrades your SDK version.
- Follow ups: These are changes that can come in follow up PRs, because 4.x.x still accepts the old names and options.
Checklist
Read the checklist first, then the sections that apply to you.
Before you upgrade
- You build with an Xcode older than 26, or your deployment targets are below iOS 15, macOS 12, tvOS 15, or watchOS 10 → Check your toolchain
- You install the SDK with CocoaPods, or a dSYM upload script uses the pod's path → Leave CocoaPods
- Your app is a React Native, Flutter, or Kotlin Multiplatform app → Upgrade wrapper packages
- You send events to a self-hosted PostHog or a reverse proxy that doesn't serve
/i/v1/analytics/events→ Prepare your proxy - You authenticate your proxy with an
Authorizationheader inrequestHeaders→ Prepare your proxy - You send events through a reverse proxy set up from PostHog's proxy guides before 29 October 2026, which strips
Authorization→ Prepare your proxy - You send events through a proxy that redirects capture requests, other than with a 307 or 308 to the same origin as
host→ Prepare your proxy - You set
projectTokento a personal API key (phx_...) → Use a project token - You capture events with a distinct ID over 200 bytes → Shorten distinct IDs
- You have a flag whose variant is an empty string, which now reads as disabled → Rename empty variants
During your upgrade
- Your build fails on a removed or renamed API, such as a
reloadFeatureFlagsclosure ormaxRetries→ Fix removed APIs - You pass
@Sendablecallbacks such assetBeforeSendin Swift 6 mode → Fix Sendable callbacks - You leave features out with package traits → Choose package traits
- You use session replay, where custom-drawn content, maps, video, and web views can now appear → Review session replay
- Your app is SwiftUI-rooted and has replay on → Review session replay
- An insight, cohort, or action uses
wireframein$sdk_debug_replay_capture_mode→ Review session replay - You rely on a plain
UIViewController'stitleas the replay screen name → Check replay screen names - Your code reads feature flag payloads and could get
nilfor a malformed one → Check flag payloads - An insight, cohort, or action uses
versionorbuildon lifecycle events → Update lifecycle filters - A cohort, insight, or action matches
$locale, which now includes the region → Update locale filters - You set event properties to
NSNull()or aniloptional → Check null properties - You filter insights, cohorts, or actions on a
null$feature_flag_responseof$feature_flag_calledto find missing flags → Check null properties - You use
$network_wifior$network_cellularon events → Check network reachability - Your users can update from a 2.x.x SDK straight to 4.x.x → Check 2.x.x upgrades
- You capture events with an empty event name, or with an event name over 200 bytes → Check dropped events
- You set an empty distinct ID in
beforeSend→ Check dropped events - You set
$cookieless_mode,$ignore_sent_at, or$product_tour_idto a value PostHog can't read, such as"maybe"→ Check dropped events - You read the SDK's debug log, for example in log-based alerts → Check dropped events
- You read
$session_idor$window_idfrom the raw request body, for example in a proxy → Check session IDs - You register a super property, or pass an event property, with the same key as one the SDK sets, such as
$os,$is_identified, or$geoip_disable, and expect the SDK's value to win → Check property precedence - You replace
event.optionsinbeforeSend, or return an event kept from an earlier call → Keep options in beforeSend - You register
$process_person_profileasfalseand expect it to keep every event personless → Check registered person processing - You rely on a
Retry-Afterlonger than 30 seconds → Check retries and batches - You use error tracking and ship your own code in a dynamic framework → Check in-app frames
- You might go back to 3.x.x after you ship 4.x.x → Plan your rollback
Follow ups
- You set legacy option properties like
$cookieless_mode→ Move to event options - You capture
$ai_*events withcapture→ Send AI events with captureAi
Before you upgrade
Check your toolchain
posthog-ios 4.x.x raises the Xcode version and the deployment targets:
| 3.x.x | 4.x.x | |
|---|---|---|
| Xcode | swift-tools-version 5.3 | 26 or later (swift-tools-version 6.2) |
| iOS and Mac Catalyst | 13.0 | 15.0 |
| macOS | 10.15 | 12.0 |
| tvOS | 13.0 | 15.0 |
| watchOS | 6.0 | 10.0 |
| visionOS | 1.0 | 1.0 |
| Installation | Swift Package Manager or CocoaPods | Swift Package Manager only |
The SDK still compiles in Swift 5 language mode, so your app can use Swift 5 or Swift 6 mode.
App Store Connect uploads already require Xcode 26. The toolchain floor mainly affects ad-hoc, enterprise, Mac, and local builds still on Xcode 16 or older.
Leave CocoaPods
posthog-ios 4.x.x isn't published to CocoaPods. The repository no longer has a PostHog.podspec, so pod 'PostHog', :git => ... can't install 4.x.x either.
posthog-ios 3.x.x versions stay installable from CocoaPods, but CocoaPods trunk becomes read-only on December 2, 2026.
Move to Swift Package Manager:
-
Remove
pod 'PostHog'from yourPodfileand runpod install. -
Add the package. In Xcode, choose File > Add Package Dependencies… and enter
https://github.com/PostHog/posthog-ios. In aPackage.swift:Swift -
Add the
PostHoglibrary to your app target.import PostHogdoesn't change. -
If a Run Script phase uploads dSYMs with
${PODS_ROOT}/PostHog/build-tools/upload-symbols.sh, change the path to${BUILD_DIR%/Build/*}/SourcePackages/checkouts/posthog-ios/build-tools/upload-symbols.sh. The old path no longer exists once the pod is gone, so symbol upload fails and crash reports lose symbolication.
Upgrade wrapper packages
Don't add the iOS SDK 4.x.x to a React Native, Flutter, or Kotlin Multiplatform app yourself. These apps get the iOS SDK through their PostHog package (@posthog/react-native-plugin, posthog_flutter, posthog-kmp).
Upgrade to the version of that package that moves to the iOS SDK 4.x.x, and follow its migration notes.
Prepare your proxy
posthog-ios 4.x.x sends data to these endpoints:
| Data | 3.x.x | 4.x.x |
|---|---|---|
| Analytics events | /batch | /i/v1/analytics/events |
| Session replay | /s/ | /s/, unchanged |
AI events (captureAi) | None | /i/v1/ai/events |
| Logs | /i/v1/logs | /i/v1/logs, unchanged |
| Feature flags | /flags | /flags, unchanged |
For AI events, see Send AI events with captureAi.
Capture v1 requests send the project token in an Authorization: Bearer <projectToken> header instead of an api_key body field.
This header replaces any Authorization header you set in PostHogConfig.requestHeaders, so authenticate your proxy with a different header, such as X-Proxy-Token. Other requests still send your Authorization header.
PostHog Cloud (us.i.posthog.com, eu.i.posthog.com) serves both capture v1 endpoints. If you self-host PostHog, make sure it serves /i/v1/analytics/events, and /i/v1/ai/events if you use captureAi, before you upgrade.
If you send events through your own reverse proxy, update it before you upgrade:
- Forward both routes. Forward
/i/v1/analytics/eventsand/i/v1/ai/eventsto PostHog. - Pass the headers through unchanged. Pass
Authorization, everyPostHog-*header,Content-Type,Content-Encoding, andUser-Agent.Authorizationholds the project token, sent asBearer <token>. PostHog answers401withoutAuthorizationand400without the others, and the batch is dropped. - Keep PostHog's credentials. If your proxy strips other credentials, keep
Authorizationvalues that start withBearer phc_,Bearer phs_, orBearer phx_, or the exactBearer <key>of an older key without a prefix. - Pass the response body through unchanged. A 2xx response whose body isn't PostHog's
{"results": {...}}drops the events instead of retrying them. - Accept request bodies up to 20 MB. AI requests are often larger than 1 MB, the default limit in nginx and ingress-nginx. On a
413from the proxy, the SDK splits the batch and drops any event that is still too large on its own.
PostHog's managed reverse proxy already does this and needs no change.
A proxy set up from PostHog's proxy guides before 29 October 2026 strips Authorization, so PostHog answers 401 and the events are dropped. Update it from the current guide.
The SDK doesn't fall back to /batch. A 404 is retried, so events stay queued until the route is served. The SDK prints one warning, even without debug. Other error statuses that aren't retried, such as 403 or 405, drop the events.
The SDK follows a 307 or 308 redirect only to the origin of host, at most 5 times, and resends the same body and headers. The origin is the same scheme, host, and port.
Any other redirect isn't followed, and the events are dropped. In 3.x.x, URLSession followed redirects to any host.
If a proxy redirects capture requests to another host, point host at the final host.
Use a project token
A personal API key (phx_...) in projectToken disables the SDK at setup, as an empty or whitespace-only token does. The SDK prints a warning that explains why, also without debug.
In 3.x.x, the SDK started and PostHog rejected every event with a 401. Use your project token (phc_...).
The SDK trims whitespace from projectToken, as in 3.x.x. To turn the SDK off in tests, use an empty token.
Shorten distinct IDs
PostHog drops an event whose distinct ID is over 200 UTF-8 bytes. Legacy capture shortened the ID to 200 characters and kept the event.
The distinct ID can come from identify(_:), the distinctId argument of capture, or beforeSend.
If you identify users with a long ID, such as a JWT or a long email address, shorten or hash it before you upgrade. Otherwise every event for that user is dropped.
Rename empty variants
A flag whose variant is an empty string reads as disabled in 4.x.x, so rename the variant before you upgrade.
PostHog no longer accepts empty variants for new flags, so only flags created earlier through the API, MCP, or Terraform are affected. /flags still returns enabled: true for them, and other PostHog SDKs can still report them as enabled.
In 4.x.x the flag reads like this:
isFeatureEnabled(_:). It returnsfalse, with or withoutdefaultValue. In 3.x.x it returnedtrue.enabled. It'sfalseingetFeatureFlagResult(_:)andgetAllFeatureFlags(). In 3.x.x it wastrue.PostHogFeatureFlagsLoaded. It leaves the flag out offlagsandvariants.- Captured events. They leave the flag out of
$active_feature_flags. In 3.x.x, events listed the flag. - The variant.
variant,getFeatureFlag(_:), and the event's$feature/<key>property still return"".
During your upgrade
Fix removed APIs
Removed and renamed APIs fail to build. For most of them Xcode names the replacement, and offers a fix-it for plain renames.
Internal and utility APIs get a plain "cannot find in scope" error, so look those up here. Objective-C names are listed where they differ.
Of the capture v1 changes, only the maxRetries rename produces a compile error. The compile error names the new property, and Xcode offers a fix-it. Since 3.73.0 it has only limited push-notification subscription retries.
Rename these configuration APIs:
| 3.x.x | 4.x.x |
|---|---|
PostHogConfig(apiKey:)ObjC: apiKey: | PostHogConfig(projectToken:)ObjC: projectToken: |
PostHogConfig(apiKey:host:)ObjC: apiKey:host: | PostHogConfig(projectToken:host:)ObjC: projectToken:host: |
config.apiKey | config.projectToken |
config.evaluationEnvironments | config.evaluationContexts |
config.remoteConfig | Delete the assignment |
config.propertiesSanitizer, PostHogPropertiesSanitizer | config.setBeforeSend(_:) (see below) |
config.dataMode = .cellularObjC: PostHogDataModeCellular | .anyObjC: PostHogDataModeAny |
config.maxRetries | config.pushNotificationSubscriptionMaxRetries |
config.storageManager, PostHogStorageManager | Methods on PostHogSDK |
Remote config is always loaded, so config.remoteConfig has nothing to set.
PostHogDataMode(rawValue: 1) now returns nil.
config.maxRetries only ever limited push-notification subscription retries.
Instead of a storage manager, use identify(_:), getDistinctId(), getAnonymousId(), getDeviceId() and reset() on PostHogSDK. There's no public way to supply your own storage manager or set the IDs directly.
Replace propertiesSanitizer with a beforeSend block:
In Objective-C, wrap each block in a BoxedBeforeSendBlock:
Replace these session replay APIs:
| 3.x.x | 4.x.x |
|---|---|
sessionReplayConfig.screenshotMode | Delete the assignment |
sessionReplayConfig.maskPhotoLibraryImages | Delete the assignment |
sessionReplayConfig.debouncerDelay | sessionReplayConfig.throttleDelay |
sessionReplayConfig.screenshotModeBackgroundCapture = true | Delete the assignment, or use sessionReplayConfig.captureMethod = .gpu (see below) |
sessionReplayConfig.screenshotModeGPUCapture = true | sessionReplayConfig.captureMethod = .gpu |
PostHogLogLevel | PostHogConsoleLogLevel |
PostHogLogEntry | PostHogConsoleLogEntry |
ObjC: PostHogLogLevelInfo | ObjC: PostHogConsoleLogLevelInfo |
ObjC: PostHogLogLevelWarn | ObjC: PostHogConsoleLogLevelWarn |
ObjC: PostHogLogLevelError | ObjC: PostHogConsoleLogLevelError |
Replay always records masked screenshots, so screenshotMode has nothing to set (see Review session replay).
sessionReplayConfig.maskPhotoLibraryImages had no effect.
captureMethod picks how each screenshot is captured: .standard (default) or the experimental .gpu. screenshotScale applies to both. In Objective-C, use PostHogSessionReplayCaptureMethodGpu.
Background capture is removed. It rendered the screen off the main thread, so a frame could show content that had already moved away from its mask. If .standard costs too much main-thread time, try .gpu.
Replace these feature flag APIs:
| 3.x.x | 4.x.x |
|---|---|
getFeatureFlagPayload(key)ObjC: getFeatureFlagPayload: | payload of getFeatureFlagResultObjC: payload of getFeatureFlagResultWithKey:sendFeatureFlagEvent: |
reloadFeatureFlags { ... }ObjC: ^{ ... } | reloadFeatureFlags { result in ... }ObjC: ^(PostHogFeatureFlagsLoaded *result) { ... } |
PostHogSDK.didReceiveFeatureFlags notification | onFeatureFlags(_:) (see below) |
To read a payload, call getFeatureFlagResult(key, sendFeatureFlagEvent: false)?.payload. In Objective-C, call [sdk getFeatureFlagResultWithKey:key sendFeatureFlagEvent:NO].payload.
The reloadFeatureFlags closure now takes a result. Write { _ in ... } if you don't use it.
result.errorsLoading is true when the reload failed or the SDK isn't set up. After a failed reload, result.variants holds the last known flags. result.errorsLoading is false when the project is over its flag quota.
Replace the didReceiveFeatureFlags notification with onFeatureFlags(_:):
In Objective-C, call [[PostHogSDK shared] onFeatureFlags:^(PostHogFeatureFlagsLoaded *loaded) { ... }]. You can subscribe before setup().
These internal and utility APIs were public only for PostHog's own React Native and Flutter SDKs, or by accident:
| 3.x.x | 4.x.x |
|---|---|
PostHogSessionManager | getSessionId(), startSession(), endSession() |
postHogSdkName, postHogVersion, config.snapshotEndpoint | No longer public |
ObjC: [PostHogSessionManager shared], setSessionId:, config.snapshotEndpoint | No longer exposed to Objective-C |
dateToMillis(_:), imageToBase64(_:_:) | No longer public |
toISO8601String(_:), toISO8601Date(_:), sanitizeDictionary(_:), deleteSafely(_:) | No longer public |
postHogiOSSdkName, Gzip, GzipError, CompressionLevel | No longer public |
UIColor(hex:), UIColor.hexDescription(_:) | No longer public |
ReachabilityError, ReachabilityChangedNotification | Removed |
getSessionId(), startSession() and endSession() are on PostHogSDK. Custom session IDs (setSessionId(_:)) have no public replacement in 4.x.x.
A wrapper SDK that must read or set postHogSdkName, postHogVersion, or config.snapshotEndpoint can use @_spi(PostHogInternal) import PostHog, with no stability guarantees.
In Objective-C, [[PostHogSDK shared] getSessionId], startSession and endSession replace the session calls.
For dateToMillis(_:), use Int64(date.timeIntervalSince1970 * 1000). For imageToBase64(_:_:), copy the code you need into your app. A wrapper SDK can still use both through @_spi(PostHogInternal) import PostHog, with no stability guarantees.
For the ISO 8601 functions, sanitizeDictionary(_:), deleteSafely(_:), postHogiOSSdkName, the gzip types, and the UIColor hex functions, copy the code you need into your app.
Use NWPathMonitor if your app needs reachability.
For the full list of changes, see the changelog.
Fix Sendable callbacks
Callbacks the SDK can call off the main thread are @Sendable in 4.x.x:
- Feature flags.
reloadFeatureFlags(_:). beforeSend. The blocks passed tosetBeforeSend(_:)onPostHogConfigandPostHogLogsConfig.- Identity.
getAnonymousId, andpushIdentityProviderand itscompletion. - Replay logs.
sessionReplayConfig.captureLogsConfig.logSanitizer. - Type aliases.
BeforeSendBlockandPostHogBeforeSendLogBlock.
In Swift 6 mode, a closure that reads or writes main-actor state no longer compiles. Swift 5 mode warns.
For reloadFeatureFlags(_:) and pushIdentityProvider, hop to the main actor:
The other callbacks must return right away, so don't read main-actor state in them.
A closure written inline in the call, such as config.setBeforeSend { event in ... }, works in both modes. A closure stored in a variable, or a method reference, depends on the language mode:
- Swift 6 mode.
config.setBeforeSend(sanitize)fails with "converting non-Sendable function value to '@Sendable ...' may introduce data races". Declare the closure asBeforeSendBlock(let sanitize: BeforeSendBlock = { ... }), or pass it in an array:config.setBeforeSend([sanitize]). - Swift 5 mode.
config.setBeforeSend([sanitize])fails with "ambiguous use of 'setBeforeSend'". Pass the closure directly instead:config.setBeforeSend(sanitize), or declare it asBeforeSendBlock.
An array of closures stored in a variable works in both modes, so you don't need to retype it as [BeforeSendBlock].
The same applies to config.logs.setBeforeSend(_:), with PostHogBeforeSendLogBlock.
Choose package traits
posthog-ios 4.x.x splits three features into Swift package traits, all on by default:
| Trait | What it includes |
|---|---|
SessionReplay | Session replay on iOS, including the bundled libwebp |
CrashReporting | Crash and uncaught-exception capture using the bundled PLCrashReporter, and out-of-memory capture |
Surveys | The survey engine and UI on iOS |
With the default traits nothing changes. To leave a feature out, list only the traits you want in your Package.swift:
Use traits: [] to leave out all three. If you leave features out, list every trait you want to keep.
In an Xcode app project, you can choose traits for a package dependency from Xcode 26.4. Check that the build leaves the feature out.
When a trait is off, its public API is removed too. Code that uses it fails to compile instead of silently doing nothing, except where noted:
SessionReplayoff. It removesconfig.sessionReplay,config.sessionReplayConfig,PostHogSessionReplayConfig, the console log types,startSessionRecording(),startSessionRecording(resumeCurrent:),stopSessionRecording(),isSessionReplayActive(), and.postHogNoMask(). TheURLSessionhelperspostHogData,postHogDownloadandpostHogUploadstill compile, but record no network requests.CrashReportingoff. It removeserrorTrackingConfig.autoCapture.captureExceptionand the rest oferrorTrackingConfigstill work.Surveysoff. It removesconfig.surveys,config.surveysConfig,PostHogSurveysConfig,PostHogSurveysDelegateand the survey display types.
.postHogMask() stays available, because it also keeps tap autocapture out of masked areas.
SwiftPM turns a trait on if any package in your dependency graph depends on posthog-ios with the default traits. You can only leave a feature out if every dependency does too.
Review session replay
Session replay always records screenshots of the screen in 4.x.x, with sensitive content masked. In 3.x.x, it recorded wireframes unless you set screenshotMode = true. Wireframe recording is gone.
If your app didn't set screenshotMode = true:
- Real pixels. Recordings show real pixels for everything that isn't masked, including custom-drawn content such as
draw(_:)views, maps, video, and charts. - Web views.
WKWebViewcontent is recorded in full when bothmaskAllTextInputsandmaskAllImagesare off. Wireframes only sent a placeholder. - Cost. Each frame uses more bandwidth and CPU than a wireframe.
If your app's window root is a SwiftUI view, replay recorded nothing in 3.x.x unless you set screenshotMode = true. With config.sessionReplay = true, these apps start recording on 4.x.x. That counts against your replay quota and may need a consent or privacy disclosure update.
$sdk_debug_replay_capture_mode is always screenshot, so update any filter on wireframe.
Check what your screens show before you ship 4.x.x. Review recordings on a test build, and add masks where needed.
Text inputs, images, and system pickers are masked by default: maskAllTextInputs, maskAllImages, and maskAllSandboxedViews are true. Set any of them to false to show that content. To hide anything else:
| To mask | SwiftUI | UIKit |
|---|---|---|
| A view and everything inside it | .postHogMask() | ph-no-capture in the view's accessibilityIdentifier |
| All text and text inputs | sessionReplayConfig.maskAllTextInputs = true (default) | same |
| Every image | sessionReplayConfig.maskAllImages = true (default) | same |
| System pickers (photos, contacts) | sessionReplayConfig.maskAllSandboxedViews = true (default) | same |
In UIKit, maskAllImages doesn't mask SF Symbols or images bundled with your app. To mask an exempt image, tag its image view with ph-no-capture. ph-no-capture also works in accessibilityLabel. To keep pixels out of recordings entirely, turn replay off with config.sessionReplay = false.
Secure-entry text fields stay masked inside a .postHogNoMask() or ph-no-mask subtree.
If you upgrade from a version before 3.93.1, masking also covers two more things, with the same UIKit exceptions:
- Content outside a masked view's bounds. Unclipped images, layer shadows, and button titles that a masked view draws outside its bounds.
- Image attachments. Image attachments in labels and text views, when
maskAllImagesis on.
Known limitation. If a masked view sits inside a view backed by your app's own
CALayersubclass, such as a Lottie animation view, the SDK can't safely read where the masked view is on screen. It masks the whole window for that frame. Fast scrolling on a screen that holds such a layer may also drop replay frames.
Check replay screen names
- Visible screen. The screen name shown for a recording comes from the screen that is visible. SwiftUI screens report their view name.
- Plain view controllers. A plain
UIViewController'stitleis no longer used as the replay screen name, so it reports no name. This includes storyboard scenes without a custom class. - Subclasses. Subclasses still report their type name without
ViewController.CheckoutViewControllerbecomesCheckout.
$screen events are named as in 3.x.x.
Check flag payloads
- Malformed payloads. A malformed, empty, or whitespace-only payload reads as
nilfromgetFeatureFlagResult(_:)andgetAllFeatureFlags(). In 3.x.x you got the raw string. The flag's value and enabled state don't change. - Bootstrapped payloads. Bootstrapped string payloads in
PostHogBootstrapConfig.featureFlagPayloadsstay strings. In 3.x.x, a bootstrapped"123"or"true"was decoded a second time and read back as a number orBool.
If your code relied on getting the raw string back, make the payload valid JSON in PostHog.
A cached bootstrapped string payload can read as nil until the next /flags response. That happens when an app's last 3.x.x launch cached the payload, got no /flags response afterwards, and no longer passes bootstrap values.
For flags whose variant is an empty string, see Rename empty variants.
Update lifecycle filters
Application Installed, Application Updated, and Application Opened no longer send version and build.
Every event already has $app_version and $app_build, so update insights, cohorts, and actions that filter on version or build.
Application Updated. It still sendsprevious_versionandprevious_build.- Cold launches. If you used "
versionis set" onApplication Openedto find cold launches, filter onfrom_background = falseinstead. - Stored events. Events already stored keep the old fields.
Update locale filters
$locale means the device's preferred language, with its region: de-CH instead of de, and fr-FR when your app only supports English. This matches Android's format and the property's definition.
If a user picks a language for your app in iOS Settings, iOS reports that language as the first preferred language, so $locale follows it.
The Android SDK 4.x.x reports the device-wide language even when a per-app language is set, so for those users $locale means different things on iOS and Android.
The new $app_language property is the language your app shows. It's the closest match to what $locale used to mean, but not always the same value. $locale sent only the language code, and $app_language sends your app's full localization name.
An app localized as de still sends de. An app localized as pt-BR or zh-Hans sends that, where $locale sent pt or zh.
If you use your own language setting instead of iOS localizations, call PostHogSDK.shared.setAppLanguage("de") at startup and whenever it changes.
Update cohorts, insights, and actions that match $locale:
- Exact matches. A filter on
$locale = destops matchingde-CH. - The language your app shows. Use
$app_language, with a regex such as^pt(-|$)if you ship regional or script localizations. - Device language. Use a regex on
$localesuch as^de(-|$), because "contains" also matchesen-DE. - Older events. Events already stored and app versions still on 3.x.x keep the old
$localeand have no$app_language.
Feature flags aren't affected. The SDK doesn't send $locale or $app_language with flag requests, so flags only see these if you set them as person properties yourself.
Check null properties
An event property set to NSNull() or to a nil optional is left out of the event instead of being sent as null. This also applies inside nested dictionaries and dictionaries in arrays, and when beforeSend sets it.
- Arrays. An array keeps a
nullelement at its position. - Empty dictionaries. A dictionary left empty is sent as
{}. - Other values.
false,0,"", and empty arrays are sent as before. NSNull(). You can still pass it.- Person and group properties. To clear a person or group property,
$set,$set_once, and$group_setstill sendnullvalues. - Flag events. A
$feature_flag_calledevent for a flag with no value has no$feature_flag_responseinstead ofnull. Filters on anull$feature_flag_responsestop matching new events without any error, so use anis not setfilter instead.
Check network reachability
posthog-ios 4.x.x detects connectivity with NWPathMonitor:
- Connections that need user action. A connection that needs user action, such as a VPN waiting for a password, counts as reachable.
- Cellular data turned off. Queues pause while cellular data is turned off for your app.
- Early events. Events captured in the first 100 ms after
setup()may leave out$network_wifiand$network_cellular.
Check 2.x.x upgrades
If an app updates from a 2.x.x SDK straight to 4.x.x, events still queued on disk by 2.x.x are deleted instead of sent. Distinct ID, anonymous ID, groups, and cached feature flags still carry over. Events created by 3.x.x aren't affected.
If 3.x.x copied a 2.x.x event into its queue and it's still unsent, 4.x.x sends it but ignores its top-level $set and message_id. Those person properties aren't set, and the event gets a new uuid unless it has a uuid field.
Check dropped events
Capture v1 checks each event on its own and drops only the invalid ones, so the rest of the batch is delivered. In 3.x.x, an empty event name or distinct ID made legacy capture reject the whole batch it was in.
The SDK drops an event with an empty event name before sending it, for example capture("") or a name beforeSend sets to "". captureAi then returns nil, and with debug on the SDK logs the first one.
The SDK doesn't check these events before sending. PostHog drops the event, and the SDK removes it from the queue:
- Empty distinct IDs. PostHog drops an event with an empty or whitespace-only distinct ID, for example one
beforeSendsets to"". - Long event names. PostHog drops an event whose name is over 200 UTF-8 bytes. Legacy capture had no limit on event name length.
- Long distinct IDs. PostHog drops an event whose distinct ID is over 200 UTF-8 bytes (see Shorten distinct IDs).
- Option values. The SDK sends option values as given, including the ones it takes from legacy option properties (see Move to event options). PostHog reads common forms of a value, such as
"false"or0for a boolean, and drops an event whose option value it can't read.
An empty or whitespace-only distinctId argument isn't dropped. Like nil, it uses the current distinct ID. identify ignores an empty or whitespace-only distinct ID. 3.x.x ignored only an empty one.
With debug on, the SDK logs how many events were dropped and why. The line has counts and PostHog's drop reasons, never event names, uuids, or properties.
There's no error callback, and the log text changed from 3.x.x, so update any log-based alerts. With debug on, the SDK no longer logs a line for each queued event, and a failed capture request no longer logs PostHog's response body. 3.x.x did both.
The SDK changes some values instead of dropping the event:
- Non-JSON values. A
NaN, infinite, or other non-JSON property value is removed before sending, and the event is still sent. - Keys that aren't strings. In a nested dictionary, a key that isn't a string, such as an
Int,Double, orBool, is sent as its string form.["scores": [1: "gold"]]is sent as{"scores": {"1": "gold"}}. - Keys with no string form. The key is removed, and the rest of the dictionary is sent. In 3.x.x, the SDK removed the whole nested dictionary.
Each event needs its own uuid. PostHog keeps the first copy in a request and drops later events with the same uuid.
The SDK generates a uuid for each capture and keeps it through beforeSend, even when the hook returns an event kept from an earlier call. You can't send a repeated uuid by accident.
Event uuids and anonymous distinct IDs are UUID v7, as in 3.x.x. The new PostHog-Request-Id header is a UUID v7 too.
The SDK sends every timestamp in UTC with 3 fractional digits, for example 2026-01-01T00:00:00.000Z, as 3.x.x did. It doesn't check for future timestamps. PostHog replaces a timestamp more than 23 hours ahead with the time it received the event.
Check session IDs
Capture v1 sends $session_id and $window_id as top-level session_id and window_id fields, not as properties. The SDK moves them out of properties for you, by the value's type:
- A string. The SDK sends it unchanged, including an empty string.
- A null value. It counts as unset, and the SDK removes it without a warning.
- Any other value. The SDK removes it and doesn't send it. With
debugon, the SDK logs a warning that names the key and the value's JSON type, never the value.
In PostHog, the events still have $session_id and $window_id, so insights, filters, and session replay work as before.
A registered $session_id overrides the SDK's session ID (see Check property precedence), which can detach events from their session replay.
Check property precedence
An event's properties are merged in this order, and later values win:
- Properties the SDK sets itself, such as
$os,$app_version,$screen_name,$is_identified,$geoip_disable, and the session replay debug properties. - Registered super properties (
register). - The properties you pass to
captureor another event-sending method. beforeSend.
In 3.x.x, the SDK's own values won over super properties. $is_identified, $process_person_profile, $geoip_disable, and the session replay debug properties also won over the properties you pass.
In 4.x.x a value you register or pass wins. For example, capture("signed_up", properties: ["$geoip_disable": false]) sends that event with GeoIP enabled even when disableGeoIp is on.
Person properties and groups are applied between steps 2 and 3:
- Per-call
userPropertiesanduserPropertiesSetOnce. They replace a registered$setor$set_oncewhole, as in 3.x.x. $setor$set_oncein the properties. It also replaces a registered one whole. The two aren't merged.- Groups. Groups set with
group()and per-callgroupsare applied there too, and replace a registered$groups. - Both at once. If you also pass
$set,$set_once, or$groupsin the properties, the per-calluserProperties,userPropertiesSetOnce, andgroupswin key by key over them. In 3.x.x,$setand$set_oncein the properties replaced the per-call values, and$groupsin the properties won per key.
$lib and $lib_version are the exception. The SDK fills them as a pair after all of the above, before beforeSend.
If $lib is missing or empty, the SDK sets both, replacing a $lib_version you passed on its own. If $lib names another library, the SDK leaves both as you set them and doesn't add its own version.
Keep options in beforeSend
Review your beforeSend hooks for the new event shape. Capture v1 reads processing settings from an options object sent next to properties, and beforeSend can read and change PostHogEvent.options.
In 3.x.x, the SDK marked person processing with the $process_person_profile property. In 4.x.x, it's the process_person_profile option, and the property isn't set.
A hook that replaces event.options without keeping that key, or returns an event kept from an earlier call, can lose the false the SDK set. That turns person processing on for anonymous users, overriding personProfiles.
Check registered person processing
A registered $process_person_profile changes person processing for every event. In 3.x.x, the SDK replaced a registered $process_person_profile with its own value, so a registered false had no effect.
In 4.x.x a registered false applies, also after identify and with personProfiles set to .always. Those events don't change the person profile, and their $set is ignored. They're still linked to the person and billed as identified events.
A registered $process_person_profile, or a process_person_profile option a wrapper SDK registers, doesn't apply to identity events: $identify, $create_alias, $merge_dangerously, $groupidentify, $set, and $set_once. With person processing off, PostHog drops $identify, $create_alias, $merge_dangerously, and $groupidentify, and keeps $set and $set_once but ignores their person update. So a registered false would stop identify, alias, group, and setPersonProperties from working.
A value you pass on the call, or set in beforeSend, still applies. To create no person profiles at all, set personProfiles to .never. The SDK then skips these calls.
Check retries and batches
| Behavior | 4.x.x | 3.x.x |
|---|---|---|
| Statuses retried | Network errors and 404, 408, 429, 500, 502, 503, and 504 responses | Also 3xx, but not 404 |
Retry-After cap | 30 seconds | None, or 5 minutes for logs |
| Wait after a failed send | Doubles, from 1 to 30 seconds | Grew by 1 second per failure |
| Request size limit | maxBatchSize events and about 5 MiB | Event count only |
| An analytics event over 1,000,000 serialized bytes | Dropped on its own | Dropped after a 413 |
In 3.x.x, the SDK didn't retry 404, and retried 3xx responses.
In 4.x.x, Retry-After sets the minimum wait before the next send, up to 30 seconds. This also applies to session replay and logs. In 3.x.x, analytics events and session replay had no cap, and logs allowed up to 5 minutes.
In 4.x.x, the wait after a failed send doubles from 1 second up to 30 seconds, with up to 25% random jitter. This applies to events, session replay, and logs.
A 4.x.x request holds at most maxBatchSize events and about 5 MiB. The SDK sends as soon as about 5 MiB of events is queued, even before flushAt is reached. In 3.x.x, batches were limited by event count only.
In 4.x.x, PostHog drops only the analytics event that is over 1,000,000 serialized bytes. With debug on, the drop line says event_too_big. In 3.x.x, the event got a 413 for its whole batch, and was dropped once the SDK had split the batch down to it.
These rules also apply:
- Other statuses. A status that isn't retried, such as a 402 when you're over your billing limit, drops the whole request. A product quota, such as for exceptions or AI events, instead drops only those events inside a 200.
- Partial retries. When the response asks to retry only some events, the SDK keeps those events queued and removes the rest.
- No retry limit. Event, session replay, and log retries have no limit, as in 3.x.x. Queued records stay until they're delivered or a full queue evicts them (
maxQueueSize, orlogs.maxBufferSizefor logs). - A 413. A 413 halves the batch and resends it, until a request carries one event. A single event that still gets a 413 is dropped. 3.x.x did the same.
- Large events. The SDK has no per-event size limit for analytics events, as in 3.x.x. An event larger than about 5 MiB is sent in a request of its own.
beforeSend. It runs when you capture the event, before it's queued, so batching, splitting, and retries never change what it sees.
Check in-app frames
Error tracking marks a stack frame as in-app only when it comes from your app's executable or from a binary in errorTrackingConfig.inAppIncludes. In 3.x.x, frames from any framework that wasn't a system framework were in-app, so third-party frameworks showed up as your code.
-
Swift packages. Code linked statically into your app, such as most Swift packages, is part of your app's executable, so it stays in-app.
-
Your own dynamic frameworks. A framework whose name starts with your app's executable name or bundle identifier stays in-app. Add any other framework that holds your code to
inAppIncludes:Swift -
Assigning
inAppIncludes. The SDK fillsinAppIncludeswith your app's bundle identifier and executable name. If your code assigns it, such asinAppIncludes = ["NetworkingKit"], that removes them, so in 4.x.x your app's own frames aren't in-app. Append with+=instead. -
3.x.x behavior. Set
config.errorTrackingConfig.inAppByDefault = true. -
Issues. Some existing error tracking issues may get a new issue location, or open as new issues.
Plan your rollback
If you ship 4.x.x and then go back to 3.x.x, 3.x.x sends the events still queued on the device. 3.x.x doesn't read capture options:
- Personless events. Events that 4.x.x marked as personless (
process_person_profile: false) are processed as person events. - Other options. Options such as
cookieless_modepassed throughoptionsare lost. - AI events. AI events queued by 4.x.x in their own queue aren't sent while the app runs 3.x.x. If you upgrade to 4.x.x again, 4.x.x sends them.
Follow ups
Move to event options
Capture v1 reads processing settings from an options object sent next to properties. capture, screen, identify, setPersonProperties, alias, group, and captureException take a new options argument:
For identify, the options apply to the $identify or $set event the call sends.
In Objective-C, use the selectors that end in options:. The selectors without options: still work.
captureWithEvent:distinctId:properties:userProperties:userPropertiesSetOnce:groups:timestamp:options:screenWithTitle:properties:options:identifyWithDistinctId:userProperties:userPropertiesSetOnce:options:setPersonPropertiesWithUserPropertiesToSet:userPropertiesToSetOnce:options:alias:options:groupWithType:key:groupProperties:options:captureExceptionWithError:properties:options:captureExceptionWithNSException:properties:options:
The legacy option properties still work. They're the $-prefixed properties that legacy capture reads as settings. When the event is sent, the SDK removes each one from properties and uses it for its option:
| Legacy option property | Option |
|---|---|
$process_person_profile | process_person_profile |
$cookieless_mode | cookieless_mode |
$ignore_sent_at | disable_skew_correction |
$product_tour_id | product_tour_id |
These rules decide which value PostHog reads:
- Precedence. An option you pass to any of these methods or set in
beforeSendwins over its legacy property. An option set toNSNull()counts as unset, so the legacy property fills it. - Person processing. When
personProfilesturns person processing off, the SDK sets theprocess_person_profileoption tofalse. Otherwise it sends neither, because PostHog processes person profiles by default. - One event. To change person processing for one event, pass the
process_person_profileoption or the$process_person_profileproperty. - Later events. Calling
group(), or passinguserProperties,userPropertiesSetOnce, orgroups, still turns person processing on for later events whenpersonProfilesis.identifiedOnly, as in 3.x.x. - Other keys. Other option keys are sent unchanged, and PostHog ignores keys it doesn't know.
- Every event. There are no global options. To set one for every event, register its legacy property, for example
register(["$cookieless_mode": true]). - Queued events. Events still queued on disk by 3.x.x are sent to capture v1 after the update, with their legacy properties moved to options.
For the changes every capture v1 SDK shares, such as event options, limits, and per-event results, see Upgrading to capture v1 SDKs.
Send AI events with captureAi
posthog-ios 4.x.x adds captureAi. It sends AI events, such as $ai_generation, to PostHog's AI endpoint (/i/v1/ai/events) instead of the analytics endpoint.
capture never sends events to the AI endpoint, even ones named $ai_*.
$ai_* events you keep sending with capture still reach PostHog through the analytics endpoint, as in 3.x.x. Moving them to captureAi gets you the AI endpoint's much larger event size limit, and a queue of their own, so large AI events don't hold up your other events.
captureAi takes the same arguments as capture, and the events go through the same beforeSend hooks:
In Objective-C, use captureAiWithEvent:distinctId:properties:userProperties:userPropertiesSetOnce:groups:timestamp:options:.
- Size. An AI event's properties can be up to 8 MiB. The SDK drops a serialized event over 8 MiB + 64 KiB, and
captureAireturnsnil. SetcaptureAiMaxEventBytesto lower the limit. It measures the whole serialized event. - Person profiles. Any
$ai_*event never creates or updates a person profile, so$setand$set_onceare ignored, and it's billed as an AI event. See the$ai_prefix. - Event names. PostHog drops an event sent with
captureAiwhose name doesn't start with$ai_. - Timeouts. AI requests time out after 60 seconds without network activity, or
captureAiTimeout. Other requests still time out after 10 seconds. - Queue. AI events are queued on disk separately from other events. Up to 100 events (
captureAiMaxQueueSize) and 50 MiB are kept, and the oldest are dropped first.maxQueueSizedoesn't apply. - Compression. AI requests are gzipped unless you set
captureAiCompressionto.none.compressiondoesn't apply. - Batching. AI events use
flushAt,maxBatchSize, andflushIntervalSeconds, like other events. A request carries up to about 5 MiB, as for analytics events (see Check retries and batches). - Flushing.
flush()andclose()also send AI events, and AI events left on disk are sent after the next launch. - Content. The SDK sends AI events unchanged. It doesn't redact or truncate prompts, outputs, or media, so use
beforeSendto remove anything you don't want to send.





