Skip to content
Docs menuInstall CentPath › Install the script

Add CentPath to a v0 app

On this page

Add CentPath to an app you build with v0 by asking v0's AI to add two next/script tags, so every page of your published app counts its visits.

Before you start

v0 builds apps with Next.js unless you ask it for another framework. In Next.js a page's head is written in code, so the HTML snippet can't be pasted as it is. The prompt below hands v0's AI the two tags of Add CentPath to Next.js instead.

In CentPath, open your site, go to Setup → Install and pick v0: the prompt there already holds your site's id.

1. Ask v0 to add it

The prompt below asks v0's AI to add the two tags to your app's root layout, exactly as written, with no package to install. Put your site's own id, from Setup → Install, in place of YOUR_SITE_ID:

Add the CentPath analytics scripts below to this Next.js app, so that every page loads them.

1. Open the root layout, app/layout.tsx (or src/app/layout.tsx), and import Script from next/script there, as the first line below does.
2. Add the two <Script> tags inside <body>, after {children}, exactly as written: the same id, strategy, src and data-site-id, and the first tag's code unchanged. Keep them together, the first above the second.
3. If the app has a pages folder and no app folder, put the first tag in pages/_document.tsx, inside <body>, and the second in pages/_app.tsx, beside the page, creating either file if the app has none, and importing Script from next/script in each.
4. Don't move them into another component. Don't install a package or a library for this.

import Script from "next/script";

<Script id="centpath-queue" strategy="beforeInteractive">
  {"window.analytics = window.analytics || Object.assign([], { q: [], goal: function () { this.q.push(arguments); } });"}
</Script>
<Script
  src="https://centpath.app/script/p.js"
  data-site-id="YOUR_SITE_ID"
  strategy="afterInteractive"
/>
  1. Copy the prompt above and paste it into your chat in v0.
  2. Send the prompt. It asks for the two tags in app/layout.tsx, the root layout every page of your app is drawn in.

If the AI changes the snippet

An AI can rewrite the tags, or move them into another component, and then no visit counts. Ask it to put them back exactly as written, or add them yourself:

  1. Open the Code tab from the preview toolbar, and open app/layout.tsx, or src/app/layout.tsx.
  2. Add the two tags from the prompt above, which hold your site's id, as Add CentPath to Next.js shows, and remove any copy the AI made elsewhere.
  3. Click Save in the Unsaved Changes bar, so v0 keeps your edit.

2. Publish your app

  1. Click Publish in the top right, and publish your app to Vercel. It goes live at its vercel.app address, or on a domain of your own you choose there.
  2. If your app was published before, open Publish and click Publish Changes. A change you make in v0 reaches your live app only when you do.

Visits to your app's preview in v0 count too, since the preview loads the scripts: Troubleshooting says why.

Verify the setup

  1. Open your published app 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. Click a link to another page of your app. Next.js changes the page without loading a new one, and CentPath counts it as a new page view: the script counts each new path, and 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 scripts into a component, or rewrote them

A plain <script> tag in a component, or a tag the AI rewrote, may never run, or may lose your site's id or the first script's code. Open app/layout.tsx in the Code tab and compare the two tags with the prompt's. If they differ, follow If the AI changes the snippet.

The preview counts visits, but your published app doesn't

Your published app still serves the version from before the scripts. Open Publish and click Publish Changes, then load a page of your published app again.

The prompt still held YOUR_SITE_ID

The scripts the AI added carry 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 app sends a Content-Security-Policy, allow https://centpath.app in its script-src and connect-src, and give both <Script> tags your nonce, as the Content Security Policy guide in Next.js's own docs shows.

For ad blockers, a wrong site id and other causes, see Troubleshooting.