- 1
Install the PostHog CLI
RequiredInstall
posthog-cli
:npm install -g @posthog/cli - 2
Authenticate the PostHog CLI
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
Output source maps for Angular
RequiredYou can configure Angular to generate source maps by adding the following to your
angular.json
file:angular.json"build": {"builder": "@angular-devkit/build-angular:application","options": {"sourceMap": {"scripts": true,"styles": true,"hidden": true,"vendor": true}}}Then, build your Angular application:
Terminalng build --configuration production Verify source map generation
CheckpointConfirm source maps are generatedConfirm that the source maps are generated in the
dist/<your-app-name>/
directory. You should see a.js.map
file for each JS bundle.- 4
Inject source map
RequiredYour goal in this step: Add metadata to associate maps with your code.Once 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/assets 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:
You should see a comment like this in your minified JS files, for example
main-IX6K2QJM.js
:JavaScript//# chunkId=0197e6db-9a73-7b91-9e80-4e1b7158db5c- 5
Upload source map
RequiredYour goal in this step: Send the processed source maps to PostHog.You 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.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.
Upload source maps for Angular
Questions? Ask Max AI.
It's easier than reading through 698 pages of documentation
Community questions
Was this page useful?
Next article
Upload source maps for web
If you serve minified bundles in production, PostHog requires source maps to generate accurate stack traces. Here are instructions to enable source map generation for popular build tools: Build Tool Documentation Vite Source Map Configuration webpack Source Map Configuration Rollup Source Map Options For other build tools, consult their documentation to enable source maps. Confirm that the served files are injected with the correct source map comment in production in dev tools.