Skip to content
measure

How to add privacy-first analytics to your Astro site (2026)

Astro is built for performance and simplicity. So is Measure. Here's how to add cookieless analytics to any Astro site in under 5 minutes — plus how to query it from your AI agent.

Guides4 min readBy Measure team

Astro is the framework of choice for developers who care about performance, clean HTML, and shipping fast. If you’re reading this, you probably already know why: minimal JavaScript, static-first rendering, and component islands that actually make sense.

Measure is analytics built with the same philosophy: lightweight, cookieless, and no bloat.

Here’s how to add Measure to any Astro site in under 5 minutes.

The 30-second version

Start a trial at lets.measure.events, grab your tracking ID, and drop this script into your Astro layout:

Astro
<!-- src/layouts/Layout.astro -->
<html>
  <head>
    <!-- your existing head content -->
    <script defer src="https://lets.measure.events/api/script/YOUR_TRACKING_ID"></script>
  </head>
  <body>
    <slot />
  </body>
</html>

That’s it. No cookies, nothing stored on the visitor’s device, so no cookie banner needed for Measure. No performance hit.

The defer attribute loads the script after your page content, so it never blocks rendering.

Why Measure works well with Astro

Astro sites are typically:

  • Statically generated or SSR-rendered — Measure handles both
  • Content-heavy — you need to know which blog posts, docs pages, and landing pages actually convert
  • Privacy-conscious — Astro developers tend to care about not shipping tracking cookies to users
  • AI-assisted — if you’re using Cursor or Claude to build your Astro site, you can query your analytics directly from your IDE

Measure fits all of these naturally.

Full integration guide

Step 1: Create your account and site

  1. Go to lets.measure.events/sign-up
  2. Create an account (magic link auth — no password needed)
  3. Add your site from the dashboard
  4. Copy your unique tracking ID

Step 2: Add the script to your layout

The best place is your root layout file — typically src/layouts/Layout.astro or src/layouts/BaseLayout.astro:

Astro
---
// src/layouts/Layout.astro
const { title } = Astro.props;
---

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>{title}</title>

    <!-- Measure — privacy-first analytics -->
    <script defer src="https://lets.measure.events/api/script/YOUR_TRACKING_ID"></script>
  </head>
  <body>
    <slot />
  </body>
</html>

Replace YOUR_TRACKING_ID with your actual tracking ID from the dashboard.

Step 3: Verify it’s working

After deploying, visit your site and open the Measure dashboard. You should see your pageview appear within a few seconds.

If you want to verify the script loaded correctly, open your browser’s Network tab and look for a request to lets.measure.events.

For Astro content collections

If your Astro site uses Content Collections (and it probably should), you might want to track which blog posts or docs pages are getting the most traffic.

Good news: the script handles this automatically. Every page load is tracked with its full URL path. In your analytics dashboard, you’ll see something like:

  • /blog/how-to-build-with-astro — 47 views
  • /docs/getting-started — 23 views
  • /blog/deploy-to-bunny-cdn — 11 views

No extra configuration needed.

For SSR / hybrid mode

If you’re using Astro’s SSR or hybrid rendering mode, the script works identically — it’s client-side JavaScript that fires on page load regardless of how the HTML was generated.

In SSR mode, you can also send server-side events through the Measure REST API (https://lets.measure.events/api/v1) if you want to track things that don’t have a page view (like form submissions, API calls, or webhook events). But for most use cases, the script is all you need.

For static site deployments (Bunny CDN, Netlify, Vercel)

If you’re deploying to a CDN (Bunny CDN, Netlify, Vercel, etc.), the tracking script loads from our servers and makes a lightweight call back. Nothing changes in your deployment process.

If you’re using Astro’s astro build with output to a static directory:

Shell
npm run build
# Deploy the dist/ directory to your CDN

Your analytics tracking is automatically included in the built HTML files.

The agent-native part

Here’s where Measure goes beyond typical analytics tools for Astro developers.

We ship a native MCP (Model Context Protocol) server. If you’re using Cursor or Claude Desktop to build your Astro site, you can connect your analytics directly. Create an API key (it starts with mk_) and add this to your Cursor or Claude MCP config:

JSON
{
  "mcpServers": {
    "measure-events": {
      "url": "https://lets.measure.events/mcp",
      "headers": {
        "Authorization": "Bearer mk_your_api_key"
      }
    }
  }
}

Then, while you’re writing code in Cursor, you can ask:

“Which of my blog posts is getting the most traffic?” “Did the performance fix I deployed yesterday change anything?” “Is anyone reading my docs — or is it mostly AI crawlers?”

Your AI assistant pulls the data directly — humans, AI agents and bots counted separately. No tab switching. No dashboard hunting.

Pricing

$29/month covers up to 40 sites, then $0.50 per site per month. 14-day trial, card required.

One simple price — see pricing.

Get started

  1. Create your account and start the 14-day trial
  2. Add one script tag to your Astro layout
  3. Deploy and start seeing real visitor data immediately

No cookies. No cookie banner for Measure. No performance overhead. Privacy-first analytics that your AI agents can actually use.

Let your agent read the numbers.

$29 a month covers 40 sites, then $0.50 a site. 14-day trial.