# Install on Astro

> Add Reveata to the base layout of an Astro site, proxy it through your own domain, and credit payments to their visits.

Astro pages share a base layout that renders `<head>`, so the snippet goes there once.

## Add it to your site

Paste the snippet in the layout that renders `<head>` for every page:

```astro
---
// src/layouts/Base.astro
---
<head>
  <script
    is:inline
    defer
    data-website-id="ws_your_tracking_id"
    src="https://reveata.com/js/script.js"
  ></script>
</head>
```

`is:inline` keeps Astro from bundling the script, so its `data-*` attributes stay on the tag. With view transitions (`<ClientRouter />`), page changes are tracked by the script.

Or build the tag with `@reveata/next/snippet` (`npm install @reveata/next`):

```astro
---
import { htmlSnippet } from '@reveata/next/snippet';
const reveata = htmlSnippet({ websiteId: 'ws_your_tracking_id', host: 'https://reveata.com' });
---
<head>
  <Fragment set:html={reveata} />
</head>
```

## Check it works

Deploy, open your site in a normal browser window with ad blockers turned off for it, then open **Realtime** in Reveata: your visit appears within a few seconds. If it doesn’t, view the page source and check that the tag is there with its `data-website-id`, then follow [Verify your installation](https://reveata.com/docs/verify-your-installation).

## Goals

Add `data-reveata-goal="signup"` to a button or link in any `.astro` component, or call `window.reveata?.('goal', 'signup')` from a script. See [Custom goals](https://reveata.com/docs/custom-goals).

## Serve it from your own domain

- **With a server adapter** (Node, Vercel, Netlify, Cloudflare), two endpoints in `src/pages` can pass the script and events through your own domain: see [Proxy with Astro](https://reveata.com/docs/proxy-astro).
- **A static site** can use its host’s rewrites ([Vercel](https://reveata.com/docs/self-hosted-proxy#vercel), [Netlify](https://reveata.com/docs/self-hosted-proxy#netlify), [Cloudflare Workers](https://reveata.com/docs/self-hosted-proxy#cloudflare-workers)), NGINX or Caddy ([Proxy through NGINX](https://reveata.com/docs/nginx#proxy-through-nginx), [Proxy through Caddy](https://reveata.com/docs/caddy#proxy-through-caddy)), or the [managed proxy](https://reveata.com/docs/managed-proxy).

## Revenue

Connect your payment provider in Reveata: see [Connect a payment provider](https://reveata.com/docs/connect-a-payment-provider). Links on your pages to Stripe Payment Links and Buy Buttons are credited to their visit with no code ([Stripe Payment Links and buy buttons](https://reveata.com/docs/stripe-payment-links)). If an endpoint of your own creates the checkout, send `window.reveata.metadata()` from the browser with that request and put the two ids in the checkout metadata, as [Install on React Router](https://reveata.com/docs/react-router#revenue) shows for an action. To send payments from your own code instead, use the [Payments API](https://reveata.com/docs/payments-api).

## Common pitfalls

- **A processed script.** Keep `is:inline` on the tag. Astro processes and bundles plain `<script>` tags, which can move the script or change its tag; `is:inline` leaves it exactly as written.
- **Several layouts.** Each layout that renders `<head>` needs the snippet, or one shared `<Head>` component that all of them use.
- **Testing on localhost.** The script ignores `localhost` unless you add `data-allow-localhost="true"`.
