Add privacy-first analytics to your React app
Set up Measure in your React app — no cookies, no cookie banner needed, one small script. Works with Vite, CRA, React Router and custom routers.
React is the most-used JavaScript framework in the world. It also has the worst analytics story. Most developers reach for a heavy cookie-based tool (a privacy headache and a big chunk of JavaScript), a full product-analytics suite (powerful but overkill for most apps), or nothing at all.
Measure is a different option: one small tracking script (about 2.5KB unminified), zero cookies, nothing stored on the visitor’s device so no cookie banner is needed for it, humans, AI agents and bots counted separately, and an MCP server so tools like Cursor and Claude can query your analytics directly.
This guide covers setup for Vite React apps, Create React App, and React Router-based SPAs.
Installation
Vite + React
Add the tracking script to your index.html:
<!-- index.html -->
<head>
<script defer src="https://lets.measure.events/api/script/YOUR_TRACKING_ID"></script>
</head>Replace YOUR_TRACKING_ID with the ID from your Measure dashboard.
Create React App
In CRA, add the script to public/index.html:
<!-- public/index.html -->
<head>
<script defer src="https://lets.measure.events/api/script/%REACT_APP_MEASURE_TRACKING_ID%"></script>
</head>Set REACT_APP_MEASURE_TRACKING_ID=your_tracking_id in your .env file.
Page views in a SPA
React Router doesn’t reload the page between routes — but you don’t need a tracking hook for that. The Measure script hooks the browser’s history API: every pushState navigation (which is what React Router, TanStack Router and most custom routers use) and every back/forward popstate is counted as a pageview. It records time on page too.
So no useEffect on location, no router wrapper. The script tag is the whole client-side setup.
Tracking conversions
There’s no browser API for custom events — the script is pageviews only, by design. You have two good options instead.
Use a destination path
Route people to a real page after the action — /thanks, /welcome, /checkout/complete. Because route changes are tracked automatically, that path’s pageviews are your conversion count:
// src/components/SignupForm.tsx
import { useNavigate } from 'react-router-dom';
function SignupForm() {
const navigate = useNavigate();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
await createAccount();
navigate('/welcome'); // counted as a pageview of /welcome
};
}Send it from your backend
For events that happen server-side (payments, webhooks), post to the REST API from your server. The API key starts with mk_ — never ship it to the browser:
// server/measure.ts
export async function recordMeasureEvent(path: string) {
await fetch('https://lets.measure.events/api/v1/events', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.MEASURE_API_KEY}`,
},
body: JSON.stringify({ site_key: process.env.MEASURE_TRACKING_ID, path }),
});
}
// recordMeasureEvent('/events/purchase');Next steps
Once your data is flowing:
- Connect the MCP server — add
https://lets.measure.events/mcp(with anmk_API key) to your Cursor or Claude setup and ask “which pages are getting the most traffic this week?” - Set up conversion paths —
/welcome,/thanks, and server-side events for anything that happens off-page - Check your AI agent traffic — Measure reports agents like ChatGPT-User, ClaudeBot and PerplexityBot separately from humans, so you can see who’s reading your docs
Measure vs a typical cookie-based tool
| Measure | Typical cookie-based tool | |
|---|---|---|
| Script size | ~2.5KB unminified | Tens of KB |
| Cookie banner | Not needed for Measure | Usually expected in the EU |
| Setup time | 5 minutes | 30+ minutes |
| SPA support | Automatic | Extra config |
| AI-queryable | ✅ MCP server | Usually ❌ |
| Price | $29/mo for 40 sites | Varies |
If you’re shipping a React app in 2026 and care about performance, privacy, or AI-assisted debugging, Measure is worth the switch. Plans are $29/month for 40 sites, then $0.50 per site per month, with a 14-day trial.
Let your agent read the numbers.
$29 a month covers 40 sites, then $0.50 a site. 14-day trial.