- 1
Download CLI
RequiredInstall
posthog-cli
:npm install -g @posthog/cli - 2
Authenticate
RequiredTo authenticate the CLI, you can call the
login
command and follow the instructions:Terminalposthog-cli loginIf 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_ID
PostHog project ID Environment settings POSTHOG_CLI_TOKEN
Personal API key with error tracking write
scopeAPI key settings Use the
--host
option in subsequent commands to specify a different PostHog instance / or region. For EU users:Terminalposthog-cli --host https://eu.posthog.com [CMD] - 3
Inject
RequiredOnce you've built your application and have bundled assets, inject the context required by PostHog to associate the maps with the served code.
Terminal# Inject metadata in files to resolve errorsposthog-cli sourcemap inject --directory ./path/to/assetsYou can verify that the metadata has been injected by checking for the
//# chunkId=...
comment in the minified code. - 4
Upload
RequiredYou will then need to upload the modified assets to PostHog.
Terminal# Upload assets to posthogposthog-cli sourcemap upload --directory ./path/to/assets💡 Tip: You can use
--delete-after
option to clean up sourcemaps after uploading them. - 5
Serve injected assets
RequiredYou 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.
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.
Upload source maps with CLI
Questions? Ask Max AI.
It's easier than reading through 698 pages of documentation
Community questions
Was this page useful?
Next article
Issues
What is an issue? Errors are captured as $exception events which means that you can create insights, filter recordings, trigger surveys, and more in the same way you can for any other type of event. Exception events are grouped into issues based on event information, such as the exception type, message, and stack trace. The data used for grouping depends on what is available. This enables you to evaluate which issues are most important and prioritize work on fixing them. We're working on…