---
title: "Install on Astro"
description: "Add XPmetric to your Astro base layout head so it loads on every route."
source: "https://xpmetric.com/docs/install/astro"
---
Astro sites should add the tracker in a **base layout** `<head>`, not inside a page component.

<TokenCallout />

## Tracking snippet

<TrackingSnippet />

## Base layout

In `src/layouts/BaseLayout.astro` (or your root layout):

```astro
---
// frontmatter
---
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <script defer data-site="YOUR_SITE_TOKEN" src="https://xpmetric.com/p.js"></script>
    <slot name="head" />
  </head>
  <body>
    <slot />
  </body>
</html>
```

Replace `YOUR_SITE_TOKEN` with your token from the dashboard.

## Why the layout?

Astro page components may not share a single `<head>`. Putting the script in the layout guarantees every route loads the tracker once.

## Verify

Run `npm run dev`, visit two different routes, and confirm both pageviews appear in XPmetric.

