# Add CentPath with Google Tag Manager

> Add CentPath as a Custom HTML tag that fires on every page, then publish your container. The first pageview proves it works.

Add CentPath to your site through Google Tag Manager, so every page that loads your container counts its visits.

## Before you start

Your site already loads your Tag Manager container on every page, and you can publish it. Tag Manager takes its own version of the snippet, made for a Custom HTML tag.

## 1. Copy your tag

In CentPath, open your site, go to **Setup** → **Install**, pick Google Tag Manager and click **Copy**. The tag 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); } });
(function () {
  var script = document.createElement("script");
  script.src = "https://centpath.app/script/p.js";
  script.setAttribute("data-site-id", "YOUR_SITE_ID");
  document.head.appendChild(script);
})();
</script>
```

## 2. Create a Custom HTML tag

1. In Tag Manager, open your container's workspace, go to **Tags** and click **New**.
2. Click **Tag Configuration** and pick **Custom HTML**.
3. Paste the tag above, with your site's id, into the **HTML** box.
4. Name the tag `CentPath`, so you can find it later.

## 3. Fire it on every page

1. Click **Triggering** and pick **Initialization - All Pages**. It fires on every page, before most other tags, so the visit counts early.
2. Click **Save**.

## 4. Publish your container

Click **Submit**, then **Publish**. Your tag reaches your live site only when you publish the container.

## Verify the setup

1. Open your live site in a new tab and load a page.
2. 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.

Your page's source doesn't show CentPath's script, since Tag Manager adds it after the page loads, and any check that reads your page's HTML can't see it either. The first pageview is the proof, or the request in your browser's developer tools: see [Check your installation](https://centpath.app/docs/verify-installation#check-the-request-in-devtools).

## Troubleshooting

### No visit arrives after you published

1. Check that the tag fires: use Tag Manager's **Preview** on your site, and look for the CentPath tag among the tags fired.
2. Check that its id is your site's own, as in step 1, letter for letter.
3. If your site has a Content-Security-Policy, see [Troubleshooting](https://centpath.app/docs/troubleshooting#a-content-security-policy-blocks-the-script).

### A goal from your page's own code throws an error

The goal queue exists once Tag Manager has run the tag. A goal your page sends earlier, in a script of its own, finds nothing there. Mark the link, button or form with a data-goal attribute instead, as [Set up goals](https://centpath.app/docs/goals) shows: the script reads it when the visitor clicks or sends the form.
