# Migrating `@posthog/react-native-plugin` ## 2.x → 3.0 If you only use the plugin through `posthog-react-native`, you don't need any JavaScript changes, but the build requirements below still apply. The API sections matter only if your code imports the plugin directly. 3.0 also gzips `posthog-react-native` 5.0's analytics, AI and log requests on iOS and Android. Apps without the plugin send them uncompressed, so install it even if you don't use session replay. ### Requirements | | 2.x | 3.0 | | --------------------------------------------------- | --------------------------------------------------------------- | --------------------- | | React Native (`react-native`, `react-native-macos`) | Any on Android, 0.71 on iOS | 0.75 or later | | iOS deployment target | 13.0 | 15.0 | | macOS deployment target | 10.15 | 12.0 | | How `posthog-ios` is installed | CocoaPods trunk, or Swift Package Manager with `posthog.useSpm` | Swift Package Manager | | `posthog-ios` version | 3.x | 4.2.2 or later 4.2.x | | `posthog-android` version | 3.x | 4.2.3 or later 4.2.x | | `posthog-react-native` version | 4.47.0 or later | 4.88.4 or later | | Xcode | Set by `posthog-ios` 3.x | 26 or later | Android `minSdk` stays at 23. `posthog-react-native` still accepts this plugin through its optional `>= 2.12.7` peer range, so upgrading the plugin alone doesn't raise it. 3.0 reads the project token only from `projectToken`, which posthog-react-native sends from 4.88.4. With an older posthog-react-native, the plugin logs `setup() needs sdkOptions.projectToken` and leaves native PostHog off: no session replay, native crash reports or fatal JavaScript error capture. JavaScript events are unaffected. Expo SDK 52 is the first Expo SDK that meets the React Native and iOS requirements. PostHog's Expo config plugin needs no changes. ### Build changes #### React Native 0.75 `posthog-ios` now installs through React Native's `spm_dependency` helper, which first ships in 0.75. **If ignored:** `pod install` fails with `requires React Native 0.75 or later`. Android builds fail below 0.71 with `Could not find com.facebook.react:react-android`. Android apps on 0.71 to 0.74 are outside the supported range: npm stops the install with an `ERESOLVE` peer dependency error unless you pass `--legacy-peer-deps`, and the Android build then needs the Kotlin 2.0 change below. On Android, React Native 0.76 and earlier apps need Kotlin 2.0 or later. The 0.74 to 0.76 templates use Kotlin 1.9, which can't read the Kotlin 2.1 libraries that `posthog-android` depends on. Plugin 2.x already had this requirement, and React Native 0.77 and later already use Kotlin 2.0.21 or later. Set the version and pin the Kotlin Gradle plugin to it: ```groovy // android/build.gradle buildscript { ext { kotlinVersion = "2.0.21" } dependencies { classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") } } ``` Expo SDK 52 uses React Native 0.76. Set `android.kotlinVersion=2.0.21` in `android/gradle.properties` and add the version to the `kotlin-gradle-plugin` classpath in the generated `android/build.gradle`. Setting only `android.kotlinVersion`, for example with `expo-build-properties`, fails with `Could not find org.jetbrains.kotlin:kotlin-compose-compiler-plugin-embeddable:1.9.25`. Both edits are in generated files, so `npx expo prebuild --clean`, or an EAS build that runs prebuild for you, wipes them. To keep them, set `android.kotlinVersion` with `expo-build-properties` and add the classpath version with a config plugin that uses `withProjectBuildGradle` from `expo/config-plugins`. Or upgrade to Expo SDK 53 or later, which uses React Native 0.79 and needs neither change. **If ignored:** the Android build fails with `Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.1.0, but the compiler version 1.9.0 can read versions up to 2.0.0.` #### iOS 15 and macOS 12 ```ruby # ios/Podfile: before platform :ios, min_ios_version_supported # ios/Podfile: after platform :ios, '15.0' ``` On React Native 0.75, `min_ios_version_supported` is 13.4, so those apps must raise the target. Raise the app target's iOS Deployment Target (`IPHONEOS_DEPLOYMENT_TARGET`) in the Xcode project to 15.0 or later too, because the 0.75 template sets it to 13.4. React Native 0.76 and later already default to 15.1. React Native macOS apps set `platform :macos, '12.0'` or later in `macos/Podfile`. Xcode 27 and later build only for iOS 15.0 and later, and React Native 0.75's own pods still set 13.4, so they fail with `The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 13.4`. Raise them in your Podfile's `post_install`: ```ruby post_install do |installer| # Keep React Native's existing react_native_post_install call here. installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.0' end end end ``` **If ignored:** `pod install` fails because the plugin needs a higher deployment target. #### `posthog-ios` 4.0 and Xcode 26 The plugin now requires `posthog-ios` 4.2.2 or a later 4.2.x version, which needs Xcode 26 or later on every iOS install path. **If ignored:** on older Xcode versions, Swift Package Manager can't resolve `posthog-ios` and the build fails. If native code in your app calls `posthog-ios` directly, it must also handle the 4.0 API removals. See the [posthog-ios migration guide](https://github.com/PostHog/posthog-ios/blob/4.0.0/MIGRATION.md). #### `posthog-ios` installs through Swift Package Manager The plugin is still a CocoaPod, but it no longer depends on the `PostHog` pod. Remove the old opt-in, which is now ignored: ```diff // ios/Podfile.properties.json { - "posthog.useSpm": "true" } ``` `use_frameworks! :linkage => :dynamic` is no longer needed for this path, so keep it only if another dependency needs it. With static linkage, `pod install` prints React Native's generic "might cause linker errors" warning for Swift packages. **Podfile options that now fail `pod install`.** React Native's helper can't add a package to these setups, so the plugin stops with an error that names the problem: - `install! 'cocoapods', :generate_multiple_pod_projects => true` - `install! 'cocoapods', :deduplicate_targets => false` - Several targets that use the plugin with different `platform` or `use_frameworks!` settings **Remove `posthog-react-native-session-replay`.** Its pod still installs `posthog-ios` 3.x from CocoaPods, which would clash with the plugin's Swift package and fail the Xcode build with `error: Redefinition of module 'PostHog'`. `pod install` now stops with an error that names the package. Uninstall it and run `pod install` again. A `pod 'PostHog'` line in your Podfile stops `pod install` the same way: remove it, and add `posthog-ios` as a Swift package to any target whose own code imports it. The plugin replaces it, and `posthog-react-native` already prefers the plugin when both are installed. The check only sees pods your Podfile adds directly to a target that uses the plugin, including autolinked packages. Another pod that depends on `PostHog` still installs, and the Xcode build then fails with `Redefinition of module 'PostHog'`. **Changes with no install error:** - **Builds fetch `posthog-ios` from GitHub.** Xcode resolves it from `https://github.com/PostHog/posthog-ios.git`, so build machines need access to it. `Podfile.lock` no longer records its version: Xcode records it in `ios/.xcworkspace/xcshareddata/swiftpm/Package.resolved`. Commit that file to keep every build on the same 4.2.x patch. Without it, each build resolves the newest 4.2.x release. Expo apps that regenerate `ios/` with `expo prebuild` don't keep the file, so their builds always resolve the newest 4.2.x. - **Your own native code may stop compiling.** React Native's helper adds the package only to the plugin's pod target, not your app target. We haven't tested this case, but if your app target has `import PostHog` and it no longer resolves, add `posthog-ios` to that target as a Swift package with a compatible version. - **Custom dSYM upload scripts can stop working.** `${PODS_ROOT}/PostHog/build-tools/upload-symbols.sh` no longer exists. Use `${BUILD_DIR%/Build/*}/SourcePackages/checkouts/posthog-ios/build-tools/upload-symbols.sh`. The `uploadNativeSymbols` build phase from the Expo config plugin already checks both paths. #### Full Swift Package Manager apps Apps on React Native's full Swift Package Manager integration, with no CocoaPods, have no Podfile to change. The plugin's `ios/Package.swift` now uses Swift tools 6.2 and requires `posthog-ios` 4.0, so build with Xcode 26 or later and keep the app's deployment target at iOS 15 or later. If `Package.resolved` still pins `posthog-ios` 3.x, resolve packages again so it moves to 4.0. The plugin pins `posthog-ios` to 4.2.2 or a later 4.2.x version (`.upToNextMinor(from: "4.2.2")`), so if your app target also adds `posthog-ios` as a package, require a 4.2.x version from 4.2.2 there too. A requirement of 4.3 or later can't resolve until the plugin raises its own. **If ignored:** Xcode can't load the plugin's package on older versions, and package resolution fails while another requirement holds `posthog-ios` at 3.x. #### `posthog-android` 4.0 If native code in your app, or a native library it uses, calls `posthog-android` directly, update it for 4.0. Code compiled against 3.x fails at runtime with errors such as `NoSuchMethodError`. The plugin requires `posthog-android` `[4.2.3, 4.3.0)` strictly, so Gradle resolves 4.2.x even when your build declares 3.x, and the build fails if another dependency requires 4.3 or later. A later plugin release raises the range once it supports 4.3. See the [posthog-android migration guide](https://github.com/PostHog/posthog-android/blob/android-v4.0.0/MIGRATION.md). ### API changes These apply only if your code calls the plugin directly. #### `setup()` reads only `projectToken` `setup()` no longer reads the deprecated `apiKey` from `sdkOptions`. Pass the project token as `projectToken`. ```ts // Before await setup(sessionId, { apiKey: 'phc_…', host }) // After await setup(sessionId, { projectToken: 'phc_…', host }) ``` **If ignored:** the plugin logs an error and native PostHog stays off. #### `start()` is removed Call `setup()`, which takes the replay settings under `sessionReplay`. Set `enabled: true`, because `start()` always started replay and `setup()` doesn't by default. ```ts // Before await start(sessionId, sdkOptions, sdkReplayConfig, decideReplayConfig) // After await setup(sessionId, sdkOptions, { sessionReplay: { enabled: true, sdkReplayConfig, decideReplayConfig }, }) ``` **If ignored:** TypeScript reports a compile error. Untyped code fails at runtime because `start` is undefined. ### Behavior changes with no build error #### `iOSdebouncerDelayMs` and `androidDebouncerDelayMs` are ignored The plugin's `setup()` now reads only `throttleDelayMs`. `posthog-react-native` still maps its deprecated options to `throttleDelayMs`, so this affects only direct calls. ```ts // Before sdkReplayConfig: { iOSdebouncerDelayMs: 500, androidDebouncerDelayMs: 500 } // After sdkReplayConfig: { throttleDelayMs: 500 } ``` **If ignored:** replay silently uses the 1000 ms default. #### Session replay records only masked screenshots `posthog-ios` 4.0 and `posthog-android` 4.0 remove wireframe capture. The plugin already forced screenshot mode, so recordings keep the same mode. If native code in your app sets `sessionReplayConfig.screenshotMode` (iOS) or `sessionReplayConfig.screenshot` (Android), remove it, because it no longer compiles. Plugin 2.x uses `posthog-android` 3.74, and `posthog-ios` 3.98 from 2.13.2 (3.92 before), so recordings also pick up these changes from the native releases since then: - On iOS, secure text inputs stay masked inside a `ph-no-mask` view. - On Android, touches inside a `ph-no-capture` view are no longer recorded. - On Android, dialog windows, which back React Native's `Modal`, are drawn into the same frame as the activity. If you upgrade from 2.13.1 or earlier, iOS recordings also pick up the changes that 2.13.2 brought: - Masking covers content a masked view draws outside its bounds, such as unclipped images, layer shadows and button titles, and with `maskAllImages`, image attachments in text. - If a masked view sits inside a view backed by its own `CALayer` subclass, such as a `lottie-react-native` animation, the SDK masks the whole window for that frame, and fast scrolling on such a screen may drop replay frames. - Touches inside a `ph-no-capture` view are no longer recorded. See [the `posthog-ios` migration guide](https://github.com/PostHog/posthog-ios/blob/4.0.0/MIGRATION.md). #### Session replay applies the project's mobile masking setting `posthog-ios` 4.2 and `posthog-android` 4.2 read the project's mobile masking setting from remote config. When it masks all text or all images, recordings mask them even if your `sessionReplayConfig` sets `maskAllTextInputs` or `maskAllImages` to `false`. The setting only adds masking. It never unmasks what your config masks. #### iOS background screenshot capture is removed `posthog-ios` 4.0 removed background screenshot capture, because a frame drawn off the main thread could show content that had already moved away from its mask. The plugin ignores `sessionReplayConfig.screenshotModeBackgroundCapture` and captures on the main thread. ```ts // Before const sessionReplayConfig = { screenshotModeBackgroundCapture: true } // After: remove it, or, with posthog-react-native 4.89.0 or later, try the experimental // GPU capture, which moves most of the capture work off the main thread const sessionReplayConfig = { iOSCaptureMethod: 'gpu' } ``` **If ignored:** replay captures with `'standard'`, and `posthog-react-native` logs a warning. #### iOS uploads pause while cellular data is off Native uploads, such as session replay and native crash reports, pause while the device is on cellular and cellular data is turned off for your app, instead of sending requests that fail. They resume when the device has a usable connection, such as Wi-Fi. #### Retries wait at most 30 seconds Session replay and native event uploads wait at most 30 seconds when PostHog answers with `Retry-After`. After a failed upload, the wait doubles from 1 second up to 30 seconds, with some random jitter. 2.x had no cap on `Retry-After`. Its wait after a failure grew by 1 second each time on iOS, and doubled without jitter on Android. #### Native crashes recorded while opted out are dropped A native crash that happens while the user is opted out is no longer sent after `optIn()`. A crash recorded while the user was opted in is still sent. #### iOS crash frames from dynamic frameworks aren't in-app In iOS native crash reports, a stack frame is in-app only when it comes from your app's executable. Your app's code and statically linked pods stay in-app. Frames from dynamic frameworks, such as Hermes and pods built with `use_frameworks! :linkage => :dynamic`, are no longer marked as your code. Some existing native crash issues may be grouped again once. See [the `posthog-ios` migration guide](https://github.com/PostHog/posthog-ios/blob/4.0.0/MIGRATION.md#check-in-app-frames). #### Native events go to capture v1 `posthog-ios` 4.0 and `posthog-android` 4.0 send the events the plugin captures natively to `/i/v1/analytics/events` instead of `/batch`: native crash reports, fatal JavaScript crashes reported natively, iOS rage clicks (`$rageclick`), and push notification opens. Events captured in JavaScript still go to `/batch`. - If you self-host PostHog or send events through a reverse proxy, make sure it serves `/i/v1/*` before you upgrade. - The proxy must pass these request headers through unchanged: `Authorization`, `Content-Type`, `Content-Encoding`, `User-Agent`, `PostHog-Sdk-Info`, `PostHog-Attempt`, `PostHog-Request-Id` and `PostHog-Request-Timestamp`. It must also return PostHog's response status, body and `Retry-After` header unchanged, because the SDKs read them to decide which events to retry or drop. A `2xx` response whose body isn't PostHog's per-event `results` drops the events. A proxy set up from PostHog's [proxy guides](https://posthog.com/docs/advanced/proxy) before 29 October 2026 strips `Authorization`, so PostHog answers `401` and drops the native events. Update it from the current guide. PostHog's managed reverse proxy needs no change. - These requests send `Authorization: Bearer `, which replaces any `Authorization` header you set in `requestHeaders`. Session replay requests still send yours, so authenticate your proxy with a different header, such as `X-Proxy-Token`. - A proxy that redirects these requests, other than with a 307 or 308 to the same origin as `host`, drops them. - A native event whose distinct ID is empty, whitespace-only or over 200 UTF-8 bytes is dropped. 2.x shortened a long ID to 200 characters and kept the event. Events captured in JavaScript still go to `/batch`, which shortens it as before, so with a long distinct ID, such as a JWT, the app keeps its JavaScript events but loses its native ones. - On iOS, a native event leaves out a property whose value is `null` instead of sending it as `null`. On Android, a `null` element in a list is sent at its position instead of being removed. `$set` and `$set_once` still send `null` values. - These events report `$locale` as the device's preferred language, as a full language tag such as `de-CH` or `zh-Hant-TW` instead of `de` or `zh-TW`, and can carry `$app_language` (see below). On iOS, 2.x reported the language your app bundle resolved, so an English-only app on a French device now sends `fr-FR` instead of `en`. A language picked for your app in iOS Settings still counts. On Android, 2.x reported `Locale.getDefault()`, so a per-app language or `Locale.setDefault()` no longer changes it. - On Android, `$locale` uses the current codes `he`, `id` and `yi` instead of the legacy `iw`, `in` and `ji`, so a value such as `in-ID` becomes `id-ID`. Update filters that match those. See [Prepare your proxy](https://github.com/PostHog/posthog-ios/blob/4.0.0/MIGRATION.md#prepare-your-proxy) and [Update locale filters](https://github.com/PostHog/posthog-ios/blob/4.0.0/MIGRATION.md#update-locale-filters) in the `posthog-ios` migration guide, and [Prepare your proxy](https://github.com/PostHog/posthog-android/blob/android-v4.0.0/MIGRATION.md#prepare-your-proxy) and [Check locale properties](https://github.com/PostHog/posthog-android/blob/android-v4.0.0/MIGRATION.md#check-locale-properties) in the `posthog-android` one. **If ignored:** a proxy that answers `404` gets a retry about every 30 seconds from each running app, and the native events stay queued on the device only until a full queue evicts them (1000 events by default), oldest first. Other errors, such as `401`, `403` or `405`, drop them. #### Native events carry `$app_language` only after you set it The plugin turns off the language detection in `posthog-ios` 4.0 and `posthog-android` 4.0, because React Native apps usually translate in JavaScript and the native SDKs can't see that language. Native events carry `$app_language` only after you call `posthog.setAppLanguage()` from `posthog-react-native` 4.86.0 or later. Call it at startup and whenever the language changes. The value also goes on JavaScript events. ```ts posthog.setAppLanguage(i18n.resolvedLanguage) ``` If your app creates PostHog clients for more than one project, native events take the language only from clients of the project the native SDK was set up for. The other clients still add it to their own JavaScript events. **If ignored:** native events and JavaScript events carry no `$app_language`, as with 2.x. #### Native surveys are left out of full Swift Package Manager apps Apps on React Native's full Swift Package Manager integration no longer bundle the native surveys from `posthog-ios`, unless another package in the app depends on `posthog-ios` with its default traits. The plugin doesn't use them, because surveys render in JavaScript, and it keeps them turned off when they are bundled. The CocoaPods path still includes the full SDK. ### Rolling back to 2.x If you ship 3.0 and then go back to 2.x, 2.x sends the native crash reports and fatal JavaScript errors that 3.0 queued on the device, through `/batch`. It doesn't read capture v1 options, so a crash that 3.0 marked as personless is processed as a person event. ### New in 3.0 - `PosthogReactNativePlugin.addBeforeSend` (Swift and Kotlin) adds a native `beforeSend` hook that also sees events the native SDKs capture themselves, such as crashes, push notification opens and session replay. ### Checklist - [ ] Your build machines use Xcode 26 or later. - [ ] posthog-react-native is 4.88.4 or later. - [ ] React Native is 0.75 or later, or Expo SDK is 52 or later. - [ ] Android apps on React Native 0.75 or 0.76, including Expo SDK 52, build with Kotlin 2.0 or later, and Expo apps keep that setting through `prebuild --clean`. - [ ] The iOS deployment target is 15.0 or later in the Podfile and the app target (and, on React Native 0.75 with Xcode 27, every pod target), and macOS is 12.0 or later if you ship it. - [ ] Full Swift Package Manager apps resolve `posthog-ios` 4.2.2 or a later 4.2.x version. - [ ] `posthog.useSpm` is gone from `ios/Podfile.properties.json`. - [ ] Your Podfile doesn't use `generate_multiple_pod_projects`, `deduplicate_targets => false`, or plugin targets with mixed platform or linkage settings. - [ ] Build machines can reach `github.com/PostHog/posthog-ios`. - [ ] Native `import PostHog` code still compiles, and custom dSYM upload scripts are updated. - [ ] `posthog-react-native-session-replay`, any `pod 'PostHog'` line, and any other pod that depends on `PostHog` are removed. `pod install` stops with an error for the first two, and the Xcode build fails with `Redefinition of module 'PostHog'` for the rest. - [ ] Direct `start()` calls now use `setup()`, and direct `setup()` calls pass `projectToken` and `throttleDelayMs`. - [ ] Reverse proxies and self-hosted instances serve `/i/v1/*`, proxies pass the `Authorization`, `Content-*`, `User-Agent` and `PostHog-*` headers and the response through unchanged and don't authenticate with `Authorization`, and they don't redirect capture requests to another origin. - [ ] Your distinct IDs are 200 bytes or shorter, or you accept that native events with longer ones are dropped. - [ ] If you want `$app_language`, your app calls `posthog.setAppLanguage()`. - [ ] Native code and native libraries that call `posthog-ios` or `posthog-android` directly are updated for 4.0.