Astro
Two options: the @antlytics/astro integration (recommended), or a plain <script is:inline> snippet.
Option A — @antlytics/astro integration (recommended)
1. Install
npm install @antlytics/astro
2. Add to astro.config.mjs
import { defineConfig } from 'astro/config'
import { antlytics } from '@antlytics/astro'
export default defineConfig({
integrations: [
antlytics({ trackingId: 'YOUR_TRACKING_ID' }),
],
})
The integration automatically injects the tracking script on every page.
Option B — Plain <script is:inline>
Add the snippet once to your root layout so it runs on every page automatically.
Prerequisites
- An Antlytics account and at least one site created in your dashboard
- The tracking ID (UUID) from Settings → Tracking Snippet
- An Astro project with a shared layout component (e.g.
src/layouts/Layout.astro)
1. Open your root layout
Open src/layouts/Layout.astro (or whichever layout wraps all your pages) in your editor.
2. Add the hosted tracker (or official integration)
Option A — official package (@antlytics/astro):
// astro.config.mjs
import { defineConfig } from 'astro/config'
import { antlytics } from '@antlytics/astro'
export default defineConfig({
integrations: [antlytics({ trackingId: 'YOUR_SITE_ID' })],
})
Option B — script tag in your layout. Replace YOUR_SITE_ID with your tracking ID:
---
// src/layouts/Layout.astro
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<slot name="head" />
<script
defer
src="https://www.antlytics.com/tracker.js"
data-tracking-id="YOUR_SITE_ID"
data-api-host="https://www.antlytics.com"
></script>
</head>
<body>
<slot />
</body>
</html>
3. Verify data is flowing
Run your Astro site (astro dev or your build preview) and open it in a browser. Check the real-time count in your Antlytics dashboard — data appears within seconds.
View transitions (Astro 3+)
If you use Astro's View Transitions (<ViewTransitions />), the hosted tracker still captures client-side navigation via History API patches and popstate. No additional configuration is required.
Troubleshooting
- Open the browser Network tab and confirm a
POSTto/api/ingest/pageviewreturns200. - Confirm the tracking ID matches Settings → Tracking Snippet in your Antlytics dashboard.
- Test in an incognito window if you have an ad blocker, or set up the first-party proxy.
See Troubleshooting for more common issues.