Docs menuInstall CentPath › Install the script
The script
On this page
The snippet is two script tags: a one-line queue, then CentPath's script. This page explains each part, what the script counts, and what it sends.
The snippet
In Setup → Install, CentPath shows this snippet with your site's own id. Copy it from there:
<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>Add it once to the <head> your pages share, as Install CentPath shows.
Attributes
| Attribute | Needed | What it does |
|---|---|---|
src | Yes | Loads the script from https://. The script sends its visits to the same address. |
data-site-id | Yes | Your site's id: the site each visit counts for. |
defer | No | Loads the script without holding up your page, and runs it once the page is read. Keep it. |
data-global | No | Renames the script's global, window.analytics, when another tool already uses that name. |
If the site id is missing or isn't a whole id, the script stops and the console says [analytics] bad data-site-id.
To use data-global, take the second version of the snippet in Install CentPath: it names ours window.centpath, in the tag and in the queue alike.
The queue
The script loads with defer, so it runs after your page's own scripts. A goal your page sends before then would have nowhere to go, and the first line is there to catch it.
- The first line creates
window.analyticswith agoalfunction that keeps each call in a queue. - When the script runs, it sends the queued goals in order, then sends each new goal at once.
The first line never replaces a window.analytics that is already there. Keep it above the script tag, as the snippet has it. Set up goals shows the goals your page can send.
Single-page apps
The script counts a page view when the page loads. In an app that changes pages without loading a new one, it counts another each time the path of the address changes: when the app calls history.pushState or history.replaceState, and when the visitor presses Back or Forward.
It compares the path alone:
- A change to the query string, like
?tab=2, isn't a new page view. - A change after a
#, like/#/pricing, isn't either: an app whose router keeps its pages after a#counts as one page, its path.
Give each screen you want counted its own path, like /pricing.
Campaign tags and ad click ids
On each page view, the script reads these UTM tags from the address and sends their values, up to 200 characters each: utm_source, utm_medium, utm_campaign, utm_term and utm_content.
It also looks for an ad click id, and sends the name of the first one it finds, never its value:
| Parameter | Added by |
|---|---|
gclid, gbraid, wbraid | Google Ads |
dclid | Google's display ads |
msclkid | Microsoft Advertising |
ttclid | TikTok |
twclid | X |
li_fat_id |
What the script sends
With each page view, the script sends:
- the page's path, like
/pricing; - the address of the page the visitor came from, as the browser gives it;
- the UTM tags and the ad click id's name, as above;
- the screen's width and height;
- the time, and a random id for the event, so an event sent twice counts once;
- whether the browser says a script drives it.
A goal sends its name, and a sale its amount, currency and order id, as your site reports them. On the page a buyer comes back to from a Stripe or Polar checkout whose success address carries the checkout's id, or on an address you mark with an order id, the script also sends that order reference, so the sale counts with no code of yours. On a Stripe, Polar or Paddle checkout link or button, the script adds a one-time reference, so a sale can be linked to the visit: see How revenue is counted.
Like every request, it also carries the visitor's IP address, user agent and preferred language. CentPath uses the IP address to look up the country, region and city, to tell a cloud server's visit from a person's, and to make a visitor hash that changes every day. It never stores the IP address.
What the script doesn't send
- No cookies, and nothing stored in the browser.
- Nothing of the page's query string beyond the UTM tags, the click id's name and, on the page a buyer comes back to after paying, the order reference your checkout puts in its address. Nothing after a
#. - No page title, text from the page, or form contents.
- No clicks, except on a link, button or form you mark with a data-goal attribute, and on the checkout links and buttons above.
The privacy policy lists everything CentPath keeps.