Upload source maps for Angular
AI wizard
Set up source map uploading automatically with our wizard by running this command in your project directory with your terminal (it also works for LLM coding agents like Cursor and Bolt):
Manual setup
- 1
Install the PostHog CLI
Required - 2
Authenticate the PostHog CLI
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
Output source maps for Angular
RequiredYou can configure Angular to generate source maps by adding the following to your
angular.jsonfile:angular.jsonThen, build your Angular application:
Terminal 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.mapfile 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 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- 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.
Terminalhog creates or reuses the release for the detected or supplied release name and version. hog tries to detect the release name and version from Git and your CI provider, but you can set them explicitly with
--release-nameand--release-version. We recommend setting the release name, and letting hog detect the version, if your project is continuously deployed (the version will be the git commit hash at build time).You can also pass
--buildto add a build number (e.g.CFBundleVersionon iOS,versionCodeon Android) to the release version, as<version>+<build>. This is optional.💡 Tip: You can use the
--delete-afteroption to clean up sourcemaps after uploading them. To inject and upload in one command, usehog error-tracking process ./path/to/assets.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
hog error-tracking inject, we won't be able to use the uploaded sourcemap to unminify or demangle your stack traces. - 6
Regenerate the service worker manifest
RequiredYour goal in this step: Keep the Angular service worker's asset hashes in sync with the injected files.Only needed if you use the Angular service workerSkip this step if your app doesn't use
@angular/service-worker.ng buildwrites a SHA-1 hash of every bundle intongsw.json.hog error-tracking injectrewrites those bundles afterwards, so the recorded hashes no longer match the files. When the service worker detects the mismatch, it rejects the new version and keeps serving the previously cached app, so your deploys silently stop reaching users.Fix this by regenerating
ngsw.jsonafter processing, using thengsw-configtool that ships with@angular/service-worker:TerminalRun
ngsw-configas the last command that touches the build output.--delete-afteralso rewrites your bundles when it strips the source map comments, so it must run beforengsw-configtoo. The last argument is your app's base href (usually/).





