measuremy.site

How to add analytics to your Astro site

This adds measuremy.site, cookieless website analytics, to a Astro site. It is one script tag of under 1 KB: no cookies, no npm package, no consent banner for the tracker. Every plan starts with a 30-day free trial, no card.

The quickest way: ask your coding agent

Paste this into Claude Code, Cursor or Codex
Add measuremy.site analytics to this project: connect the measuremy.site MCP server at https://a.measuremy.site/mcp for all my projects (claude mcp add --scope user; it signs in with OAuth, no key, and one sign-in covers every site), then tell me how to sign in. Details: measuremy.site/llms.txt

The agent connects to measuremy.site, you sign in through your browser, and it adds the tag below to the right file for you. To do it by hand, follow the steps.

1. Get your site key

Start a free trial and add your domain. The Setup tab shows your snippet with your site key filled in. The key is public and can only record visits, so it is safe in your source code.

2. Add the script tag

The quickest way is the integration, which adds the tag to every built page (and leaves it out of astro dev):

npx astro add astro-measuremysite

Then give it your site's key in astro.config.mjs: measuremysite({ key: "pk_..." }), or set PUBLIC_MEASUREMYSITE_KEY in .env. For a new site, npm create astro@latest -- --template developeron29/astro-measuremysite-starter has it set up.

Or add the tag by hand, to the <head> of the layout every page uses, usually src/layouts/Layout.astro. Mark it is:inline so Astro leaves it as it is instead of bundling it:

---
const { title } = Astro.props;
---
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>{title}</title>
    <script is:inline defer src="https://a.measuremy.site/t.js" data-key="YOUR_SITE_KEY"></script>
  </head>
  <body>
    <slot />
  </body>
</html>

If some pages don't use that layout, add the tag to their layouts too. Navigations made through the History API are counted automatically.

3. Check it works

Publish the change, then open your live site. The first visit from your own domain verifies it and the visit shows up on the dashboard within seconds. Visits from localhost aren't counted, so test on the deployed site.

4. Track signups and other conversions

From any client-side script, after the action completes:

<script>
  document.querySelector("#signup-form")?.addEventListener("submit", () => {
    window.measuremysite?.track("signup");
  });
</script>

Or, with no JavaScript, add data-measuremysite-event="signup_click" to any link, button or form.

Any event counts as a conversion for the channel the visitor came from.

Other platforms, and funnels and campaign links, are in the install guide.

Try it on your site

30-day free trial, no card. Plans from $9/month. Paste one sentence into your coding agent, or add one script tag yourself.

Start free trial See the live demo

Add measuremy.site analytics to this project: connect the measuremy.site MCP server at https://a.measuremy.site/mcp for all my projects (claude mcp add --scope user; it signs in with OAuth, no key, and one sign-in covers every site), then tell me how to sign in. Details: measuremy.site/llms.txt

Free tools

All free tools

More guides