# Add CentPath to Laravel

> Paste the snippet into the Blade layout your Laravel pages share, or the root template of an Inertia app.

Add CentPath to the Blade layout your Laravel pages share, so every page rendered with it counts its visits.

## 1. Copy your 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. Paste it into your layout's head

1. Open the Blade file that holds your pages' `<head>`. In an Inertia app, with React, Vue or Svelte, it is the root template, `resources/views/app.blade.php`. Otherwise it is your main layout, often under `resources/views/layouts`.
2. Paste the snippet inside `<head>`, before `</head>`. Blade leaves it as it is, since it holds no Blade syntax: no echo braces and no `@` directive.
3. Keep the two lines together, the first above the second. The first line keeps any goal your page sends before CentPath's script has loaded, and the script sends it once it runs. [Set up goals](https://centpath.app/docs/goals) shows how to send one.

If some of your views don't use this layout, add the snippet to their own `<head>` too.

## 3. Deploy your app

Deploy your app the way you always do, so your live pages carry the snippet.

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

In an Inertia app, a link changes the page without loading a new one, and Inertia updates the browser's history as it does. CentPath counts each new path as a page view, as it does the visitor's Back and Forward. Visits from `localhost` count too, whenever your development server's pages load the snippet.

## Troubleshooting

### Setup still waits for the first pageview

1. Load a page of your live site, not your development server.
2. Open that page's source in your browser and search for your site's id. If it isn't there, that page doesn't render the layout that holds the snippet: add it to the layout the page uses, and deploy again.
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`).

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