Skip to content
measure

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.

Guides3 min readBy Measure team

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:

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:

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:

JSX
// 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:

TypeScript
// 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:

  1. Connect the MCP server — add https://lets.measure.events/mcp (with an mk_ API key) to your Cursor or Claude setup and ask “which pages are getting the most traffic this week?”
  2. Set up conversion paths — /welcome, /thanks, and server-side events for anything that happens off-page
  3. 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
MeasureTypical cookie-based tool
Script size~2.5KB unminifiedTens of KB
Cookie bannerNot needed for MeasureUsually expected in the EU
Setup time5 minutes30+ minutes
SPA supportAutomaticExtra config
AI-queryable✅ MCP serverUsually ❌
Price$29/mo for 40 sitesVaries

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.