# Install on Replit

> Add MetricRaven to a Replit app by asking Agent or editing the HTML head, then publish.

Source: https://metricraven.com/docs/install-replit  
Markdown: https://metricraven.com/docs/install-replit.md  
Section: Installation guides

Ask Replit Agent to add the tag, or paste it into your app's HTML head, then publish.

## Ask Agent

1. **Send this prompt to Agent**

   Replace `YOUR_SITE_ID` with the public site ID from your site's **Settings → Install** card. The site ID is public and safe in browser code; never put your secret key in a page.

   ```text title="Prompt"
   Add this analytics script to every page of the app. Load it once for the whole app,
   in index.html or the root layout (with next/script in a Next.js app), never from a single
   page or component. Keep the src and data-site-id attributes exactly as written:

   <script defer src="https://metricraven.com/js/script.js" data-site-id="YOUR_SITE_ID"></script>
   ```

2. **Publish**

   Choose **Publish** at the top right of the workspace (or republish). The development preview is a private, temporary URL that isn't your live app.

## Or edit the file yourself

Open the file that renders your page head and paste the tag before `</head>`:

- A Vite or plain HTML app: `index.html` (in full-stack apps it may sit in a `client` folder).
- Next.js: follow the [Next.js](https://metricraven.com/docs/install-nextjs) guide.
- Flask or Django: your base template; see [Django](https://metricraven.com/docs/install-django).

```html title="index.html"
<script
  defer
  src="https://metricraven.com/js/script.js"
  data-site-id="YOUR_SITE_ID"
></script>
```

> **Verify it works**
>
> Open your live website in a normal browser window (not an automated or embedded one). In the browser's Network panel, look for `script.js` and then a request to `/api/v1/collect` whose response contains `ok: true`. Open your site's **Traffic** tab and choose **Refresh**; the selected dates must include your visit.
>
> Nothing showing? See [Troubleshooting](https://metricraven.com/docs/troubleshooting).

## Notes

- Only hostnames listed in your site's **Settings → General → Site** domains (and their subdomains) are accepted. To also count visits on a platform address such as `your-app.replit.app`, add it there; otherwise those requests are refused with `domain_not_allowed`.
- On the Starter plan a published app expires after 30 days. When it does, tracking stops with it.
- AI edits can drift. After each publish, open your live app, view the page source and check the tag is still in `<head>` with its `data-site-id` unchanged.
- Click between a few pages and check the Network panel shows one `/api/v1/collect` pageview per navigation. Two per click means the tag is loaded twice.

Optional script attributes are listed in [Install & verify](https://metricraven.com/docs/install). To exclude your own visits, see [Exclude your visits](https://metricraven.com/docs/exclude-visits).
