# Let an AI coding agent install Crustat

Paste a short prompt into your AI coding agent, give it your site ID when it asks, and check the one file it changed.

Source: https://crustat.com/docs/getting-started/ai-agent

## When this helps

If you build your site with an AI coding agent, like Claude Code, Cursor or GitHub Copilot, you can hand it the install. The prompt below tells the agent exactly what to add and where. The agent asks you for one thing: your site ID.

## Quick start: a prompt you can copy here

Copy this prompt and paste it into your agent as it is. The agent asks you for your site ID first, then does the install.

```text
Add Crustat analytics to this project.

First, ask me for my Crustat site ID and wait for my answer. It is a 16-character code made of letters, digits, - and _, shown in Crustat under Site settings → Install, next to "Site ID". Don't guess it and don't use a placeholder.

Then put this exact line in the <head> of every page, with SITE_ID replaced by the ID I gave you:

<script defer src="https://stats.crustat.com/script.js" data-site="SITE_ID"></script>

Rules:
- Add it once, in the shared layout or base template that renders <head> for all pages (for example index.html, a root layout, a base template or the theme header), not page by page.
- Apart from the site ID, keep the line exactly as it is. Don't change the src, and don't remove defer.
- A plain <script> tag in the HTML is simplest. A framework's script component (for example next/script) works too, as long as it keeps the same src and data-site.
- If the project already has a Crustat line, replace it with this one instead of adding a second.
- If the site uses Cloudflare Rocket Loader or a plugin that combines or delays scripts, add data-cfasync="false" to the tag or exclude it from that plugin.
- If the site sets a Content-Security-Policy, allow https://stats.crustat.com in script-src and connect-src.

When you're done, tell me which file you changed and show me the line as it ended up.
```

Have your site ID ready: it's the 16-character code on **Site settings → Install**, next to **Site ID**, with a **Copy ID** button. Don't have a site yet? [Add Crustat to your website](https://crustat.com/docs/getting-started/install) shows where to start.

## Or copy the prompt with your line already in it

Crustat can also fill in the ID for you:

1. In Crustat, open your site and go to **Site settings → Install**.
2. Under **Where does** your domain **run?**, pick the **AI agent** tab.
3. Click **Copy the prompt**. To read it first, click **See the prompt**.

The same prompt also appears on your site's stats page while it's waiting for its first visit.

## What the prompt asks for

Both versions say the same thing. The prompt is in English in every language of the app, since agents follow English instructions best. It gives the agent your exact line and these rules:

- **Once, in the shared layout.** Add the line in the template that renders `<head>` for every page, like `index.html`, a root layout, a base template or the theme header. Not page by page.
- **Exactly as it is.** Don't change the `src` or the `data-site` value, and keep `defer`.
- **A plain script tag is simplest.** A framework's own script component, like the one in Next.js, works too, as long as it keeps the same `src` and `data-site`.
- **No duplicates.** If there's already a Crustat line, replace it instead of adding a second one.
- **Rocket Loader and script combiners.** If the site uses Cloudflare Rocket Loader, or a plugin that combines or delays scripts, add `data-cfasync="false"` or exclude the line from that plugin.
- **Content-Security-Policy.** If the site sets one, allow `https://stats.crustat.com` in `script-src` and `connect-src`.

It ends by asking the agent to tell you which file it changed and to show you the line as it ended up.

## Use it

1. Open your project in your agent.
2. Paste the prompt and send it. With the quick-start prompt, the agent asks for your site ID: paste it in.
3. Read the agent's answer. Check the file it names and the line it shows. The `data-site` value should match the **Site ID** on your Install page.
4. Publish the change the way you usually do.

## Check that it worked

Open your live site, not `localhost`, and wait about a minute. On **Site settings → Install** the badge changes from **No visits yet** to **Working since** and the day.

If it doesn't change, ask the agent to show you where the line ended up in the built page, or check it yourself: view the page source of your live site and search for `crustat`. Then see [visits aren't showing up](https://crustat.com/docs/getting-started/troubleshooting).

## Using a framework?

For Astro and Next.js there are also ready-made packages. You can point your agent at them instead: [Astro](https://crustat.com/docs/getting-started/astro), [Next.js](https://crustat.com/docs/getting-started/nextjs). Either way works.
