Docs menuInstall CentPath › Install the script
Add CentPath to a Lovable app
On this page
Add CentPath to an app you build with Lovable by asking Lovable's AI to add the snippet, so every page of your published app counts its visits.
Before you start
Lovable builds newer apps on TanStack Start, and older ones on React and Vite. The prompt below fits both, so you don't need to know which one your app is.
1. Ask Lovable to add it
The prompt below asks Lovable's AI 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 Lovable 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 it to put them back exactly as written, or check and add them yourself:
- Open your project's code in Lovable's code editor. Anyone who can edit your project can read the code there on any plan; editing it there needs a paid Lovable plan.
- In an app built with Vite, open
index.htmland paste your snippet inside<head>, as Add CentPath to React and Vite shows. Remove any copy the AI made elsewhere, so there's one place to change it. - In an app on TanStack Start, open
src/routes/__root.tsxand search for your site's id: that line should be CentPath's script, with an inline script holdingwindow.analyticsabove it. If either is missing, send the prompt again in a new message.
2. Publish your app
- Click Publish in the top-right corner of the editor, next to Share, then Publish again in the dialog. Your app goes live at its
lovable.appaddress, or on your own domain if your plan has one. - If your app was published before, open the same dialog and click Publish changes. Your live app keeps the version you published until you do.
Visits to your app's preview in Lovable 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
The AI 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 the AI rewrote may lose your site's id or the first line. Open the file the AI 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. Open Publish and click Publish changes, then load a page of your published app again.
The prompt still held YOUR_SITE_ID
The snippet the AI 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 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 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.