Add analytics to Astro.
Astro ships mostly static HTML with islands of JS, so your analytics needs to load once in the layout and not get hoisted or stripped by the bundler. smolanalytics is two script tags in the head of your base layout, marked is:inline so Astro leaves them alone. It autocaptures pageviews, clicks and errors with no code, and you query it in plain English.
<!-- src/layouts/Layout.astro (your base layout), inside <head> -->
<head>
<!-- ...existing head... -->
<script is:inline src="https://YOUR-INSTANCE/sdk.js"></script>
<script is:inline>smolanalytics.init("WRITE_KEY", { host: "https://YOUR-INSTANCE" })</script>
</head>is:inline is required, otherwise Astro tries to process and bundle the script. Put it in the base layout every page wraps with so it loads site-wide.
how do I add analytics to astro?
Astro ships mostly static HTML with islands of JS, so your analytics needs to load once in the layout and not get hoisted or stripped by the bundler. smolanalytics is two script tags in the head of your base layout, marked is:inline so Astro leaves them alone. It autocaptures pageviews, clicks and errors with no code, and you query it in plain English.
Most Astro sites are content-first, so the metrics that count are which pages get read, how far people scroll, and which outbound or CTA clicks fire. Autocapture gives you scroll depth, the full element chain on every click, and JS errors from your interactive islands without touching component code. When an island does something meaningful, call smolanalytics.track("newsletter_signup") from the client script inside that component.
It fits Astro because it stays out of the build. The is:inline tags load as plain HTML in the head of your base layout, so they run on every statically generated page with no adapter and no hydration cost. Self-host the open-source binary free or go hosted from 29 dollars a month, run it cookieless with no consent banner, and ask your numbers in plain English from the dashboard bar or your editor over MCP.
Honest pricing: 14-day full trial, no credit card. Then Solo $29/mo, never metered on seats or sites. Overage is $5/million with an emailed receipt, the dashboard never locks, and self-hosting the single Go binary is free forever (MIT).
Add analytics to Astro tonight.
One snippet, or one endpoint. Tomorrow morning the verdict tells you which part of the funnel to fix.