Astro
Add Humblytics Analytics to an Astro Site
1 · Sign up (or log in)
Visit humblytics.com → Start Free Trial. Finish signup—or log in to your existing workspace.
2 · Add your website in Humblytics
In the sidebar, click Add Website.
Domain – enter
your-domain.com(omithttps://andwww)Site Name – internal label (e.g.
Astro-Site)
Copy the snippet from Install Tracking Code:
html
<!-- Start Humblytics Tracking Code -->
<script async src="https://app.humblytics.com/hmbl.min.js?id=YOUR_ID_HERE"></script>
<!-- End Humblytics Tracking Code -->Keep this tab open—we'll return and click Verify Website once the tag is live.
3 · Add the script to your Astro project
Option 1: Direct script tag (simplest)
Best for: Quick setup, works with all Astro features
Open your main layout file:
src/layouts/BaseLayout.astroOr
src/layouts/Layout.astro
Add the script before
</head>:
astro
Note: is:inline prevents Astro from bundling/optimizing this script, ensuring it loads as-is.
Option 2: Using environment variables (recommended)
Best for: Managing different environments (dev, staging, production)
Add to
.env:
env
Update your layout:
astro
Add to
.env.production(or your hosting platform's env vars):
env
Option 3: Production-only tracking
Best for: Disabling analytics during development
astro
Option 4: With View Transitions (if using Astro's SPA mode)
Best for: Sites using View Transitions for SPA-like navigation
If you're using <ViewTransitions /> in your layout:
astro
Note: The astro:page-load event ensures tracking works with client-side navigation.
Multiple layouts
If your site uses multiple layout files, either:
Add the script to each layout, or
Create a shared component:
Create src/components/Analytics.astro:
astro
Use in layouts:
astro
Note: Replace YOUR_ID_HERE with your actual project ID from Humblytics.
4 · Build and deploy
Development:
bash
Production:
bash
Deploy to your hosting platform:
Vercel:
vercel --prodNetlify:
netlify deploy --prodCloudflare Pages: Push to Git
Or use Astro's adapters for SSR deployments
5 · Verify installation
Return to Humblytics and click Verify Website
Open your live Astro site in a private/incognito window
Refresh once
Within ~30 seconds you should see a green Verified badge and live visitor count
If verification fails, check:
Astro-specific issues:
You built and deployed to production (not testing
npm run dev)Environment variable is set correctly (check deployment platform)
Script has
is:inlinedirective (otherwise Astro may bundle it incorrectly)If using View Transitions, verify
astro:page-loadlistener is presentCheck build output for errors:
npm run build
General issues:
Script ID matches your project in Humblytics
View page source (right-click → View Page Source) and search for "humblytics"
Open Developer Tools (F12) → Network tab and search for
hmbl.min.jsNo ad-blockers or browser extensions are blocking the script
Debug in Astro:
bash
6 · Explore & optimize
Dashboard – view traffic, top pages, and referrers
Heatmaps – auto-generated click and scroll insights
Experiments – create A/B tests directly from Humblytics
Last updated
Was this helpful?