Adding privacy-first analytics to Angular apps in 2026
Set up Measure in your Angular 17/18 app via index.html or APP_INITIALIZER, with automatic SPA pageview tracking and MCP for AI-powered queries.
Angular apps have specific needs when it comes to analytics. The framework’s strong opinions about dependency injection, routing, and initialization mean you want analytics that fits cleanly into Angular’s architecture — not a script tag bolted onto index.html and forgotten.
Measure’s script is a couple of KB, sets no cookies, stores nothing on the visitor’s device — so you don’t need a cookie banner for it — and ships with an MCP server so tools like Cursor and Claude Code can query your analytics directly. Here’s how to wire it into an Angular 17/18 app properly.
Option 1: Simple script injection via index.html
The fastest way to get started. Add the script to your src/index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>My Angular App</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script defer src="https://lets.measure.events/api/script/YOUR_TRACKING_ID"></script>
</head>
<body>
<app-root></app-root>
</body>
</html>That’s enough on its own: the script tracks the initial load, every Angular Router navigation (it listens for pushState/popstate), and time on page.
Option 2: APP_INITIALIZER (the Angular way)
For cleaner integration that plays well with Angular’s lifecycle, use APP_INITIALIZER in your app.config.ts:
// app.config.ts
import { ApplicationConfig, APP_INITIALIZER } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
function initMeasure(): () => void {
return () => {
if (typeof document !== 'undefined') {
const script = document.createElement('script');
script.defer = true;
script.src = 'https://lets.measure.events/api/script/YOUR_TRACKING_ID';
document.head.appendChild(script);
}
};
}
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
{
provide: APP_INITIALIZER,
useFactory: initMeasure,
multi: true,
},
],
};This approach works properly with Angular Universal (SSR) since the typeof document check prevents the script from running on the server.
SPA pageview tracking
Angular is a single-page app framework — navigating between routes doesn’t reload the page. You don’t need to do anything about that: Measure’s script picks up History API navigation (pushState and popstate), so every route change is recorded as a pageview with its own path. No Router subscription, no tracking service.
Tracking conversions
There’s no browser event API to call. Conversions are tracked as pages: route people to /thanks or /welcome after a signup and watch that path. For things that happen on your backend, send an event to the REST API (POST https://lets.measure.events/api/v1/events with your mk_ API key) from the server.
A lightweight script
Angular developers care about bundle size. You’ve carefully optimized your lazy-loaded routes, tuned your bundle analyzer, and set up tree-shaking. Then a typical analytics tag loads far more JavaScript than the page it’s measuring needs.
Measure’s script is a couple of KB, always deferred, and loaded from outside your bundle. For Angular apps targeting Lighthouse scores above 90, that’s one less thing to optimize.
MCP server: query your Angular app’s traffic from Claude or Cursor
This is where Measure earns its differentiation in 2026. Once you have the MCP server configured, your AI coding tools become analytics dashboards.
In Cursor or Claude Code, you can ask:
“What are the top 5 pages by traffic this week?” “Which referrers drove traffic to /pricing?” “How much of my traffic is AI agents versus humans?”
Most analytics tools require you to leave your editor and click through a dashboard. Measure answers in the same context you’re already working in.
Create an API key in Measure (it starts with mk_), then add the MCP server to your Cursor or Claude Code config:
{
"mcpServers": {
"measure-events": {
"url": "https://lets.measure.events/mcp",
"headers": {
"Authorization": "Bearer mk_your_api_key"
}
}
}
}Getting started
- Sign up at lets.measure.events/sign-up — 14-day trial, then $29/month for up to 40 sites
- Create a site and copy your tracking ID
- Add the script via
index.htmlorAPP_INITIALIZER - Optional: connect the MCP server for AI-powered queries in Cursor/Claude Code
Setup time: under 10 minutes. Bytes added to your Angular bundle: 0 (the script loads externally with defer).
Let your agent read the numbers.
$29 a month covers 40 sites, then $0.50 a site. 14-day trial.