Upload source maps for React
- 1
Install the PostHog CLI
RequiredInstall
posthog-cli: - 2
Authenticate the PostHog CLI
RequiredTo authenticate the CLI, you can call the
logincommand and follow the instructions:TerminalIf you are using the CLI in a CI/CD environment such as GitHub Actions, you can set environment variables to authenticate:
Environment Variable Description Source POSTHOG_CLI_ENV_IDPostHog project ID Environment settings POSTHOG_CLI_TOKENPersonal API key with error tracking writescopeAPI key settings Use the
--hostoption in subsequent commands to specify a different PostHog instance / or region. For EU users:Terminal - 3
- 4
Inject source map
RequiredOnce you've built your application and have bundled assets, inject the context required by PostHog to associate the maps with the served code.
TerminalThe CLI will create or reuse the release for the detected or supplied project and version. The CLI will try to detect project and version information, but you can set them explicitly with
--projectand--version. We recommend setting the project, and letting the CLI detect the version, if your project is continuously deployed (the version will be the git commit hash at build time). Verify source map injection
CheckpointConfirm source map comments are presentConfirm that the served files are injected with the correct source map comment in production in dev tools.
JavaScript- 5
Upload source map
RequiredYou will then need to upload the modified assets to PostHog.
TerminalThe CLI reuses the release stored during injection, so you don't need to pass
--projector--versionagain.💡 Tip: You can use
--delete-afteroption to clean up sourcemaps after uploading them.Serve injected assets
You must serve the injected assets in deployed production app. The injected metadata is used during error capture to identify the correct source map to use. We suggest you upload source maps right after your production build in CI.
If you serve a copy of the bundled assets as they were prior to running
posthog-cli sourcemap inject, we won't be able to use the uploaded sourcemap to unminify or demangle your stack traces.