Upload source maps for React Native
The Xcode and Gradle upload scripts in posthog-react-native 4.90.0 and later upload with hog, PostHog's CLI. When hog isn't installed, they upload with posthog-cli and warn that posthog-cli is deprecated. Earlier versions of the scripts only run posthog-cli, version 0.7.8 or later. Native symbol uploads move to hog with the native SDKs' tooling, as native crash symbolication explains.
If you are using React Native Web, ensure source maps are generated
Then use our standard CLI approach to inject and upload them.
- 1
Install hog
Required - 2
Authenticate
RequiredLog in to PostHog. This opens your browser, where you approve the login:
TerminalIf posthog-cli is already logged in on this machine, import that login instead:
TerminalThese CI providers can upload with the job's OIDC token, so you don't store a personal API key in CI.
- Logged in with
hog auth login, run this once in the repository:
Terminal- An organization admin approves the request in PostHog.
- Add the
hostandprojectIdthat hog prints toposthog.json, and add the snippet it prints to the job.
In GitHub Actions, the job needs the
id-token: writepermission:YAMLRemove any personal API key from the job. A key wins over the OIDC token.
Set these environment variables in the job:
Environment variable Description Source HOG_HOSTThe PostHog host to connect to, such as https://eu.posthog.com[default: https://us.posthog.com]Project settings HOG_PROJECT_IDPostHog project ID Project settings HOG_PERSONAL_API_KEYPersonal API key with the error_tracking:writescopeAPI key settings hog reads only the
HOG_*names. The PostHog build plugins and upload scripts still pass the oldPOSTHOG_CLI_*names to hog for now, with a warning for each one. Ahogcommand you run yourself needs theHOG_*names. The migration guide lists each rename. - 3
Inject
RequiredExpo 50 or laterAutomatic source map injection works only in React Native apps using Expo 50 or later, as it relies on Expo's built-in debug ID injection.
Create or update the metro.config.js file in your app's root directory so that it looks like this:
diff - 4
Upload
RequiredAutomatic source map uploading is handled through the Gradle build process on Android and the Xcode build process on iOS.
EAS UpdatesIf you are using EAS Updates, source maps must be uploaded manually after running the update command. The automatic upload via Gradle/Xcode only runs during native builds, not during OTA updates.
TerminalThe
distfolder is the default output directory for EAS updates.- Expo: Update the app.json file in your app's root directory.
Expo Plugins that add modifications can only be used with prebuilding and managed EAS Build.
If you can use the
posthog-react-native/expoplugin, skip steps 2 and 3. If not, proceed with steps 2 and 3.Add the
posthog-react-native/expoplugin under theexpo.plugins.diffIf your project has a checked-in
ios/directory, run or rerun the iOS prebuild after adding or upgrading the plugin:TerminalThis reapplies the config plugin to the existing Bundle React Native code and images build phase. When upgrading from
posthog-react-native4.61.0 or earlier to a newer version, the plugin automatically migrates the previously generated PostHog command. You do not need to editproject.pbxprojmanually.The plugin accepts the following options:
Option Type Default Description disableSandboxingbooleantrueiOS only. When true, setsENABLE_USER_SCRIPT_SANDBOXING=NOon your main app target's Xcode build configurations duringexpo prebuild. This lets the source map upload script read.git/(for release metadata) and lets stock Expo projects build without manually declaring input/output files on every script phase.skipOnConflictbooleanfalseAdds --skip-on-conflictto the Hermes source map upload (hog error-tracking upload, orposthog-cli hermes uploadwithout hog) on iOS and Android. Use this when the same build can upload the same source maps more than once and you want duplicate uploads to be skipped instead of failing. Requiresposthog-react-native4.49.1 or later. WhenuploadNativeSymbolsis enabled, it also applies to native iOS dSYM uploads: a build whose dSYM already exists in PostHog with different content skips the upload and keeps the existing symbols instead of failing. The dSYM behavior requiresposthog-react-native4.56.1 or later,posthog-ios3.64.7 or later, andposthog-cli0.7.12 or later.dotenvFilestring– Path to a dotenv file containing your CLI credentials (API key, project ID, optional host), relative to the project root or absolute. During expo prebuildthe path is wired into every upload hook: as thePOSTHOG_CLI_DOTENV_FILEXcode build setting on iOS, plusHOG_DOTENV_FILEfromposthog-react-native4.90.0, and as aposthog.dotenvFileentry inandroid/gradle.propertieson Android. The JavaScript source map, dSYM, and ProGuard/R8 mapping uploads all read credentials from the file regardless of how the native build is started. Real environment variables take precedence and a missing file only logs a warning, so the same config works unchanged in CI. Requiresposthog-react-native4.60.0 or later. Uploads with posthog-cli also needposthog-cli0.8.4 or later (older versions ignore the variable).Example opting out of the sandbox change:
JSONWhen to opt outdisableSandboxing: falseis intended for organizations with compliance requirements that forbid disabling Xcode's user script sandbox. With the opt-out:- iOS source map uploads continue to work, so errors still symbolicate
- Git metadata will not be attached to iOS releases (the UI chip shown for Android rows will be missing on iOS rows)
- Your project must already have every build-phase script (yours, Expo's, CocoaPods-generated) declaring its inputs and outputs, otherwise the build will fail
This setting only affects build-time scripts on the build machine. Your shipped app's runtime security is unchanged.
Example skipping duplicate JavaScript source map uploads:
JSONExample reading CLI credentials from a gitignored
.envfile at build time:JSON.envposthog-cli reads the
POSTHOG_CLI_API_KEY,POSTHOG_CLI_PROJECT_ID, andPOSTHOG_CLI_HOSTnames instead. The upload scripts still pass those names to hog for now, with a warning to rename them. While native symbol uploads run posthog-cli, keep both sets of names in the file.- Android: Update the
/android/app/build.gradlefile from your app's root directory so that it looks like this:
diff- iOS: Update the
/ios/$yourProjectName.xcodeproj/project.pbxprojfile (replace$yourProjectNamewith your project's actual name). You need to locate theBundle React Native code and imagesbuild step.
To do this through Xcode, open your project in Xcode, go to the project settings, navigate to Build Phases, and select Bundle React Native code and images. Use the command that matches your installed
posthog-react-nativeversion.posthog-react-native4.61.0 and earlierdiffposthog-react-nativenewer than 4.61.0diffIf you are not using the Expo plugin (step 1), you will need to also disable User Script Sandboxing for the upload script to work. In Xcode, go to Build Settings, search for User Script Sandboxing (
ENABLE_USER_SCRIPT_SANDBOXING) and set it to No. This is required because the script needs to read.git/for release metadata and run hog, which are not allowed under Xcode's script sandbox. - 5
Native crash symbolication
OptionalThe steps above upload JavaScript source maps, which symbolicate exceptions thrown in your JS/TS code (including Hermes bytecode). They do not cover native iOS and Android crashes.
If you enable native crash autocapture (
errorTracking.autocapture.nativeCrashes,errorTracking.autocapture.androidNdkCrashes, or both), you also need to upload native debug symbols at build time so those crash reports are readable. This reuses the native PostHog SDKs' own tooling:Platform Crashes Symbols Uploaded by iOS All native crashes ( nativeCrashes)dSYMs posthog-ios's upload-symbols.sh. The posthog-ios 3.x version that@posthog/react-native-plugininstalls runs posthog-cliAndroid Java/Kotlin crashes ( nativeCrashes)ProGuard/R8 mapping files, for minified release builds The com.posthog.androidGradle plugin, which uploads with hog from 1.9.0 and also injects a matching map-id into the appAndroid C/C++ (NDK) crashes ( androidNdkCrashes).sodebug symbolsThe same Gradle plugin Source-code contextincludeSource(orPOSTHOG_INCLUDE_SOURCEon iOS) also uploads your native source files. On iOS, crash frames then show the surrounding code. On Android, it uploads your C/C++ sources with the.sodebug symbols. Java/Kotlin crashes have no source-code context, because the ProGuard/R8 mapping upload doesn't include sources.Three pieces are required end-to-endSymbolicated native crashes need all three of these working together:
- Build-time – upload native symbols (this section).
- Runtime – enable
errorTracking.autocapture.nativeCrashes(anderrorTracking.autocapture.androidNdkCrashesfor Android NDK crashes) and install@posthog/react-native-plugin. - Server-side – enable the Enable exception autocapture setting in your project's error tracking settings.
Prerequisites
JavaScript source maps upload with hog from
posthog-react-native4.90.0, but native symbol uploads use the native SDKs' tooling, which picks its own CLI:- iOS dSYMs:
@posthog/react-native-plugin3.0 installs posthog-ios 4.2.x, whoseupload-symbols.shuploads with hog from 4.2.4. Plugin 2.x installs posthog-ios 3.x, which runs only posthog-cli. - Android, bare React Native: the Gradle plugin uploads with hog from 1.9.0. Earlier versions run posthog-cli.
- Android, Expo: from
posthog-react-native4.90.0, the config plugin adds Gradle plugin 1.9.0, which uploads with hog. Earlier versions add 1.8.0, which runs only posthog-cli.
Where a native upload runs posthog-cli, keep posthog-cli installed and logged in next to hog:
npm install -g @posthog/cli, thenposthog-cli login. The Android.sodebug symbol upload needsposthog-cli0.7.32 or later.In CI/CD builds (such as EAS Build), set
HOG_PERSONAL_API_KEYandHOG_PROJECT_ID(andHOG_HOSTfor EU) for hog. posthog-cli reads onlyPOSTHOG_CLI_API_KEY,POSTHOG_CLI_PROJECT_ID, andPOSTHOG_CLI_HOST, so set both sets from the same secrets while native uploads run posthog-cli. The job's OIDC token in GitHub Actions, GitLab.com, and Depot CI only covers the uploads that run hog. See the migration guide for the full list of names.For local builds, log in with both
hog auth loginandposthog-cli login. To supply credentials from a file instead, use thedotenvFileplugin option described in the Upload step. It covers the native symbol uploads on both platforms too. On bare React Native, you get the same behavior by addingposthog.dotenvFile=../.envtoandroid/gradle.properties(relative paths resolve against theandroid/directory; the mapping upload needsposthog-android-gradle-plugin1.4.0 or later) and, on iOS, definingHOG_DOTENV_FILEandPOSTHOG_CLI_DOTENV_FILEbuild settings (for example$(SRCROOT)/../.env) on your app target. posthog-cli reads onlyPOSTHOG_CLI_DOTENV_FILE.The
posthog-react-native/expoconfig plugin can wire up native symbol upload for you during prebuild. It's opt-in – setuploadNativeSymbolstotruein your app.json:JSONWhen enabled,
expo prebuildadds an iOS dSYM-upload build phase and applies thecom.posthog.androidGradle plugin on Android. Fromposthog-react-native4.78.0, it also enables the plugin's Android.sodebug symbol upload for NDK crashes. If your project was prebuilt earlier with acom.posthog:posthog-android-gradle-pluginclasspath older than 1.5.0, the next prebuild bumps it.To additionally upload native source files, pass an options object instead of
true. On iOS, this adds source-code context to crash frames. On Android, it bundles the C/C++ sources with the.sodebug symbols, fromposthog-react-native4.78.0:JSONIf you aren't using the Expo config plugin, wire up the uploads manually.
iOS
In Xcode, add a Run Script build phase to your main app target and place it last so it runs after the dSYM bundle is produced. The
upload-symbols.shscript ships with the transitiveposthog-iosdependency. Use the script path that matches your iOS dependency path. With@posthog/react-native-plugin3.0 and later, use the SwiftPM path on every iOS dependency path, including CocoaPods. The CocoaPods path applies only to plugin 2.x on CocoaPods.Then, for your Release configuration, set these build settings:
- Debug Information Format (
DEBUG_INFORMATION_FORMAT) to DWARF with dSYM File, so dSYMs are generated. - User Script Sandboxing (
ENABLE_USER_SCRIPT_SANDBOXING) to No, so the script can locate dSYMs, read.git/for release metadata, and runposthog-cli.
To also upload native source files for source-code context (iOS only), prefix the script with
POSTHOG_INCLUDE_SOURCE=1:This is the same flow as the iOS dSYM upload guide, which has a full Xcode walkthrough.
Android
In
android/build.gradle, add the PostHog Android Gradle plugin to yourbuildscriptdependencies (and make suremavenCentral()is in thebuildscriptrepositories):android/build.gradleThen apply the plugin in
android/app/build.gradle:android/app/build.gradleThe plugin uploads ProGuard/R8 mapping files and injects a matching map-id during your release build, so native Android crash stack traces are deobfuscated.
If you enable
androidNdkCrashes, also upload the.sodebug symbols so NDK crash stack traces resolve. This needs the Gradle plugin 1.5.0 or later. Enable the upload inandroid/app/build.gradle:android/app/build.gradleSee upload native debug symbols (NDK) for the full options, including source context.
Troubleshooting
Build fails with Sandbox: bash deny(1) file-read-data
You probably have { disableSandboxing: false } set in your plugin options, or your Xcode project has ENABLE_USER_SCRIPT_SANDBOXING = YES set explicitly somewhere that overrides the plugin. Stock Expo projects need the sandbox disabled because several build-phase scripts (Expo's expo-configure-project.sh, various CocoaPods-generated scripts) don't declare all their inputs. Either remove the opt-out, or declare inputs on every script phase and keep sandboxing on.





