Tracking
A ~1.8KB compressed tracker for automated pageviews and declarative custom events.
Pageviews
The script tag records a pageview on initial load and listens to client-side single-page app routing.
It hooks into pushState, replaceState, and popstate, so
framework navigation (Next.js, Vite, React, Vue, Svelte) is measured automatically without extra configuration.
Going back or forward to another page counts, whether or not the browser kept that page in memory.
A page the browser prerenders counts only if someone opens it, and what it tracked while hidden is sent then.
<script defer data-site="YOUR_SITE_CODE" src="https://www.staats.ai/s.js"></script>
Custom events
Add a data-staats attribute to any clickable HTML element. No site-side JavaScript needed:
the tracker uses a single delegated event listener to capture interactions dynamically:
<button data-staats="signup_click">Start free trial</button>
<a href="/download" data-staats="download_click">Download App</a>
For non-click interactions or programmatic flows, call window.staats:
window.staats('checkout_completed')
Ask your agent to track something and it adds the attribute in the same change as the feature. Name events so they read on their own (see the naming conventions below): a name is all a later question has to go on.
Purchases
A custom event can carry what was paid. Send it from the page a buyer reaches after paying, with the amount in the currency’s main unit (29.99, not 2999 cents) and its three-letter code:
window.staats('purchase', { revenue: 29.99, currency: 'USD' })
The tracker loads after the page, so a call that runs as the page loads would come too early. Put this line before the script tag, once, and calls made before the tracker is ready are sent when it is:
<script>window.staats=window.staats||function(){(window.staats.q=window.staats.q||[]).push(arguments)}</script>
Revenue is kept per currency, exactly as sent, and never converted. A purchase is a custom event in every other way: it counts toward your monthly events, and funnels and journeys see it by name. Revenue comes with paid plans; on free, your agent sees how many purchases there were.
Your agent sees revenue next to where buyers came from: the source, campaign, referrer and landing page of their first visit that day (UTC), never the payment page they return from. Visitors aren’t followed across days, so someone who first came on Monday and paid on Tuesday is credited to Tuesday’s first visit. A purchase with no earlier visit that day, such as a checkout that crossed midnight UTC, shows as unattributed.
Purchases come from the visitor’s browser, so revenue is close to your payment provider’s figures but not the same. A content blocker, or a buyer who closes the tab before the page loads, means one isn’t counted; a buyer who reloads the page sends it again; refunds aren’t taken off. Use it to see what brings buyers, not as your books.
Error tracking
The tracker also listens for uncaught JavaScript errors and unhandled promise rejections. Capture is strictly passive: the tracker never intercepts, suppresses, or rethrows anything, so console output, stack traces, and any other error tooling on the page behave exactly as if the tracker were absent.
Error messages are sanitized on our servers before anything is stored: emails, tokens, keys,
card-shaped numbers, UUIDs, IPs, and long quoted strings are replaced with placeholders, the
message is truncated to 200 characters, and one sample is kept per distinct error, not per
occurrence. Errors are grouped by a fingerprint of the sanitized message and source file. Line numbers
and bundler content-hashes are deliberately excluded from the fingerprint (they change on
every build), so the same error stays one group across deploys; the sample shown always
carries the most recent source and line.
Ask your agent what broke to read them (what_broke), since a commit or a time you name.
Error events never touch your monthly events. They draw on a separate monthly error allowance
(5,000 on free; paid plans include more, shown on your account page), with the same 25% buffer
events get. On top of that they are bounded by 5 per page load in the browser
(the budget resets on each navigation) and per-visitor and per-site rate limits on the
server, so even a site-wide error storm can never touch the events your plan pays for. Error events are
analytics-internal: they are excluded from the CSV traffic export, and errors thrown by
cross-origin scripts without crossorigin attribution (which browsers report
only as an empty "Script error." stub) are ignored entirely, and so are errors thrown
by browser extensions (chrome-extension:// and friends): those are a visitor's
extension misbehaving, not your site, so they never reach your error list.
Event naming conventions
Use clean, lowercase snake_case names that follow a target_action pattern:
pricing_click, trial_started, export_csv_click. Event names are
capped at 120 characters. Consistent naming ensures your agent can query and build funnels over them reliably.
What each event records
| Field | Description |
|---|---|
| type & name | pageview, custom with the event name, or error with the error's fingerprint |
| revenue & currency | On a purchase only: the amount and three-letter currency code the site sent |
| path | Page pathname (clean URLs without query strings) |
| referrer domain | External referral hostnames only (internal hops filtered) |
| utm parameters | Campaign attribution (utm_source, utm_medium, utm_campaign) |
| ad click detection | An ad network's click parameter (gclid, wbraid/gbraid, msclkid, ttclid, twclid, li_fat_id, fbclid) fills in the source when utm_source is absent: google, microsoft, tiktok, twitter and linkedin also claim a paid medium unless utm_medium is set; facebook claims none, since Meta apps append it to organic shares too. The click token itself never leaves the page. |
| device & browser | Derived from User-Agent: desktop / mobile / tablet |
| operating system | Derived from User-Agent: iOS, Android, ChromeOS, Windows, macOS, or Linux |
| country | Inferred via client timezone (no IP geolocation services; see Data & Privacy) |
| visitor | Pseudonymous hash rotating daily (zero cookies, zero persistent storage) |
Known search engine crawlers and automated bots are filtered out at ingestion, and browsers that report being driven by test tools
(navigator.webdriver, which Playwright, Puppeteer and Selenium set by default) send nothing. Neither
counts toward your event quota.
Excluding your own visits
Your own browsing counts the same as anyone else's. On a quiet site that can be most of the traffic, and it is enough to trigger a false anomaly. Run this once in the browser console, on the site you want to skip:
localStorage.staats_ignore = 'true'
The flag is stored per browser and per domain, so repeat it in every browser you use and on each
site you own. To start counting yourself again, run
localStorage.removeItem('staats_ignore').
Local development is already excluded. Pages opened from file:// and any host on
localhost are never recorded, so your dev server stays out of production numbers with
no setup. window.staats() still exists there, and in an ignored browser, so your own calls to it never throw.
Leave the script off your 404 page
If your 404 page carries the script tag, every mistyped URL and every crawler probe is recorded as a pageview for a page that does not exist, and those paths then sit in your stats looking like real ones. Serve your 404 page without the snippet.