# Add CentPath to a Bolt app

> Ask Bolt's AI to add the snippet with a prompt you paste, publish your site, and add it by hand in Code view if the AI changes it.

Add CentPath to an app you build with Bolt by asking Bolt's AI to add the snippet, so every page of your published site counts its visits.

## Before you start

Bolt can build your app with any JavaScript framework. The prompt below fits an app built with Vite, which keeps its pages' head in `index.html`, and an app that writes its head in code. If your app has an `app/layout.tsx` file, it's a Next.js app: send the prompt in [Add CentPath to a v0 app](https://centpath.app/docs/v0) instead.

## 1. Ask Bolt to add it

The prompt below asks Bolt's AI to put the snippet in the head every page of your app loads, exactly as written, with no package to install. It ends on the snippet with `YOUR_SITE_ID` in place of an id: paste your own snippet from **Setup** → **Install**, which holds your site's own id, over its last two lines.

```text
Add the CentPath analytics snippet below to this app, so that every page loads it.

1. Put both tags inside the <head> of the HTML page that every page of the app is served from. In a Vite app, that is the index.html that Vite builds the app from.
2. Paste the two tags exactly as written, together, the first above the second. Don't rewrite them, don't add type="module", and don't move them into a component.
3. In an Astro app, add is:inline to both tags, so Astro leaves them as written.
4. If the app has no such HTML page because it writes its <head> in code (as a TanStack Start or Next.js app does), add the two scripts to the <head> its root route or layout writes, in the framework's own way: the first as an inline script with exactly this code, the second with exactly this src, data-site-id and defer.
5. Don't install a package or a library for this.

<script>window.analytics = window.analytics || Object.assign([], { q: [], goal: function () { this.q.push(arguments); } });</script>
<script defer src="https://centpath.app/script/p.js" data-site-id="YOUR_SITE_ID"></script>
```

1. Copy the prompt above and paste it into the chat of your Bolt project.
2. In CentPath, open your site, go to **Setup** → **Install** and click **Copy**. In the chat, select the prompt's last two lines and paste your snippet over them.
3. Send the prompt.

### If the AI changes the snippet

An AI can rewrite the two lines, or move them into a component, and then no visit counts. Ask it to put them back exactly as written, or add them yourself in Bolt's Code view:

1. Click the code icon at the top of the screen to open Code view. Editing there needs Chrome or another Chromium-based browser on a computer: in Safari or on a phone, Code view is read-only.
2. In an app built with Vite, open `index.html` from the file list and paste your snippet inside `<head>`, as [Add CentPath to React and Vite](https://centpath.app/docs/react) shows. In a Next.js app, follow [Add CentPath to Next.js](https://centpath.app/docs/nextjs) instead.
3. Click **Save**. Bolt builds your app again with the change.

Remove any copy the AI made elsewhere, so there's one place to change it.

## 2. Publish your site

1. Click **Publish** in the top-right corner, then **Publish** again in the menu that opens. Your site goes live at a `bolt.host` address, or on your own domain on a paid Bolt plan.
2. If your site was published before, open the **Publish** menu and click **Update**. A change you make in Bolt reaches your published site only when you do.

Use the buttons rather than asking the AI to publish: Bolt's help says a prompt to publish uses up tokens.

Visits to your app's preview in Bolt count too, since the preview loads the snippet: [Troubleshooting](https://centpath.app/docs/troubleshooting#visits-from-localhost-or-a-staging-site-are-counted) says why.

## Verify the setup

1. Open your published site in a new tab and load any page.
2. Back in CentPath, look under the steps in **Setup** → **Install**. **Waiting for your first pageview…** turns into **First pageview received.** once the visit arrives.
3. If it said **First pageview received.** before you started, your site has had visits already: look for this one in your dashboard instead. Reload it, and the visit shows in the **Visits** feed, usually within a minute.
4. Open another page of your app through its links. When your app changes the page without loading a new one, CentPath counts each new path as a page view, as it does the visitor's Back and Forward.

A change to the query string alone, like `?tab=2`, isn't a new page view.

## Troubleshooting

### The AI moved the snippet into a component, or rewrote it

A script tag that a component draws in the browser may never run, and a tag the AI rewrote may lose your site's id or the first line. Open the file the AI changed in Code view and compare the two lines with your snippet from **Setup** → **Install**. If they differ, follow [If the AI changes the snippet](#if-the-ai-changes-the-snippet).

### The preview counts visits, but your published site doesn't

Your published site still serves the version from before the snippet. Open the **Publish** menu and click **Update**, then load a page of your published site again.

### The prompt still held YOUR_SITE_ID

The snippet the AI added carries `YOUR_SITE_ID` instead of your site's id, so the script sends nothing, and your browser's console says `[analytics] bad data-site-id`. Ask the AI to replace `YOUR_SITE_ID` with your site's id, from **Setup** → **Install**, then publish again.

### A Content-Security-Policy blocks the script

If your site sends a Content-Security-Policy, allow `https://centpath.app` in its `script-src` and `connect-src`, and let the snippet's first line run (a nonce or a hash in `script-src`). [Troubleshooting](https://centpath.app/docs/troubleshooting#a-content-security-policy-blocks-the-script) shows each step.

For ad blockers, a wrong site id and other causes, see [Troubleshooting](https://centpath.app/docs/troubleshooting).
