Docs menuInstall CentPath › Install the script
Add CentPath to a Replit app
On this page
Add CentPath to a web app you build on Replit by asking Replit Agent to add the snippet, so every page of your published app counts its visits.
Before you start
Replit Agent can build an app in many languages and frameworks. This guide is for a web app whose pages open in a browser: the prompt below fits one served from an HTML file, as a React app built with Vite is, and one 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 instead.
1. Ask Replit Agent to add it
The prompt below asks Replit Agent 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.
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>- Copy the prompt above and paste it into the chat of your Replit project.
- 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.
- 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 Agent to put them back exactly as written, or add them yourself:
- In the Project Editor, open the file tree and find your app's
index.html. In an app built with Vite, it's the one Vite builds the app from. - Paste your snippet inside
<head>, as Add CentPath to React and Vite shows. In a Next.js app, follow Add CentPath to Next.js instead. - Remove any copy Agent made elsewhere, so there's one place to change it.
2. Publish your app
- Click Publish in the upper-right corner of the Project Editor, and publish your app. It goes live at a
replit.appaddress, or on a domain of your own you connect. - If your app was published before, click Republish. A change you make in the Project Editor doesn't replace your live app until you do.
Visits to your app's preview in Replit count too, since the preview loads the snippet: Troubleshooting says why.
Verify the setup
- Open your published app in a new tab and load any page.
- Back in CentPath, look under the steps in Setup → Install. Waiting for your first pageview… turns into First pageview received. once the visit arrives.
- 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.
- 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
Agent 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 Agent rewrote may lose your site's id or the first line. Open the file Agent changed and compare the two lines with your snippet from Setup → Install. 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 snippet. Click Republish, then load a page of your published app again.
The prompt still held YOUR_SITE_ID
The snippet Agent 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 Agent to replace YOUR_SITE_ID with your site's id, from Setup → Install, then republish.
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 let the snippet's first line run (a nonce or a hash in script-src). Troubleshooting shows each step.
For ad blockers, a wrong site id and other causes, see Troubleshooting.