Skip to main content
To add CrispStats to an Angular app, paste the script tag inside <head> in src/index.html, the page the app is served from. Angular’s router changes the URL through the History API, which the script watches, so every route change is counted with no router code. You need your site’s public key, which starts with cs_pk_. Find it in your site’s settings under Tracking code, on the HTML tab. The key is safe to publish. There is no npm package to install.

Add the script

1

Add the tag to src/index.html

src/index.html
Replace the key and the domain with yours. Keep it a tag in index.html rather than an entry in the scripts option of angular.json: the script reads its options from the data- attributes of its own <script> tag. Keep defer and do not add type="module".
2

Add types (optional)

Save crispstats.d.ts from TypeScript in src/ so window.crispstats is typed. Check that the include list of tsconfig.app.json covers it.
3

Build, deploy and open your app

ng serve runs on localhost, which the script ignores. Run ng build, deploy, then open your live app in a normal browser window.

Router setups

The same URL twice in a row is one pageview, so a redirect that replaces the URL with itself does not add a view. See single-page apps.

Check that it works

  • In your browser’s developer tools, the Network tab shows d.js loading from in.crispstats.com and a POST to https://in.crispstats.com/e on the first load and on each route change. The collector answers 202.
  • In CrispStats, Settings, Tracking code shows Receiving events., and the visit appears in Realtime within seconds.
To see events on ng serve, add data-debug and localhost in data-domains while you develop. Every event is logged in the console and nothing is sent. See localhost and testing.

Send custom events

Call the global from a component. The optional call (?.) keeps the app working when an ad blocker stops the script:
src/app/upgrade-button.component.ts
For clicks you can also put data-cs-event="upgrade clicked" on the element in the template, with no TypeScript. See declarative events.

FAQ

No. The script tag is the whole install, and route changes are seen without router hooks. Call window.crispstats directly where you need custom events.
Hash location keeps the route after #, which the script drops unless the tag has data-hash. Add it and redeploy.
Call await window.crispstats?.id() in the click handler that starts checkout and send it with the request. See visitor id at checkout.

Next steps

Single-page apps

How route changes, hash routing and engagement are tracked.

Identify signed-in users

Tie visits to your own user id.

TypeScript

Types for the global and the queue stub.
Angular details (src/index.html as the page the app is served from, and withHashLocation() using the URL fragment instead of the History API) checked against https://angular.dev/reference/configs/file-structure and https://angular.dev/api/router/withHashLocation on 2026-11-23.
Last modified on November 23, 2026