# Install CentPath

> Add the CentPath script once to the head your pages share, check that visits arrive, and fix what stops them.

Add one script to your site, and CentPath counts every page that loads it.

## 1. Copy the snippet

In CentPath, open your site, go to **Setup** → **Install** and click **Copy**. The snippet you copy holds your site's own id, so every visit counts for the right site:

```html
<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>
```

## 2. Add it to the head your pages share

Add this once to the `<head>` your pages share — usually your site's layout or template, as you would with Google Analytics. Every page that loads it is counted; a page you build by hand needs it on that page too. It sets no cookies, so traffic needs no consent banner.

1. Open the file that holds your site's `<head>`, the one every page uses.
2. Paste the snippet inside `<head>`, before `</head>`. The first line lets your pages send goals before the script has loaded, so keep both lines together.
3. Save and publish your site, so the live pages carry the snippet.

[The script](https://centpath.app/docs/script) explains each of the snippet's attributes and what it sends.

## Verify the setup

1. Open your live 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, as below.
4. Open your dashboard, or reload it: the visit is in **Visitors** and in the **Visits** feed, usually within a minute.

Visits from `localhost` and from a staging copy of your site count too, whenever their pages load the snippet.

[Check your installation](https://centpath.app/docs/verify-installation) shows more ways to check a page, and [Troubleshooting](https://centpath.app/docs/troubleshooting) what to do when visits don't arrive.

## Troubleshooting

### You can't find your snippet

Each site has its own snippet, under **Setup** → **Install**. If your site isn't in CentPath yet, [add your site](https://centpath.app/docs/add-a-site) first.

### Setup still waits for the first pageview

1. Load a page of your live site, not a preview your site builder keeps for itself.
2. Open that page's source in your browser and search for your site's id. If it isn't there, the page doesn't load the snippet: publish your change, or add the snippet to the template that page uses.
3. 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`).

### You test with an automated browser

A browser driven by a script, as test tools drive one, says so to every page, and CentPath counts none of its visits. Open your site in your own browser to see a visit arrive.

### Another tool already uses window.analytics

If you use Segment, or another tool that uses `window.analytics`, use this version instead, so the two don't clash. It names ours `window.centpath`: send goals through `window.centpath` wherever these pages say `window.analytics`. Copy it, then put your site's own id in place of `YOUR_SITE_ID`: **Setup** → **Install** shows your id under the steps, with **Copy** beside it.

```html
<script>window.centpath = window.centpath || 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" data-global="centpath"></script>
```
