← All IntegrationsIntegration

Analytics for Astro

Astro ships zero JavaScript by default — only hydrating interactive islands when needed. BetterMeter's sub-1KB tracker fits perfectly into this philosophy. Add it to your base layout and get full page analytics across your content site, blog, or documentation.

Add to your base layout

Astro uses layout components for shared page structure. Drop the tracker script into your BaseLayout.astro and every page inherits it automatically.

src/layouts/BaseLayout.astro
---
interface Props {
  title: string;
}
const { title } = Astro.props;
---

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>{title}</title>
  </head>
  <body>
    <slot />
    <script
      defer
      data-site="your-domain.com"
      src="https://bettermeter.com/api/script"
    ></script>
  </body>
</html>

View Transitions support

Astro's View Transitions API turns multi-page sites into SPA-like experiences. BetterMeter detects navigation events fired by the View Transitions API, so page views are tracked accurately even when Astro swaps content without a full page load.

Built for content sites

  • 01 Blog analytics — See which posts get the most traffic, where readers come from, and how AI crawlers index your content.
  • 02 Documentation sites — Track which docs pages are most visited. Identify gaps where users drop off.
  • 03 Content collections — Astro's content collections give you structured content. BetterMeter gives you structured analytics to match.
  • 04 AI traffic visibility — See when ChatGPT, Claude, or Perplexity cite your content. Understand how AI drives traffic to your site.

Why Astro + BetterMeter

Astro is built for speed. Adding a heavy analytics suite defeats the purpose. BetterMeter's tracker is under 1KB, uses no cookies, requires no consent banner, and loads asynchronously. Your Lighthouse scores stay at 100. Your analytics stay complete.

Zero JS Default
Matches Astro's philosophy
View Transitions
SPA nav tracked
Content Sites
Blogs, docs, marketing
AI Crawlers
GPTBot, ClaudeBot, etc.
Island-Friendly
No hydration needed
Lighthouse 100
No perf impact