Skip to content

Web

Tracking script

The core script is about 2 KB (gzip), loads asynchronously and sets no cookies. It works on any website.

Install

Add the script to the <head> of every page. Pageviews are collected automatically; window.trackd is then available for custom events and revenue.

<script defer src="https://trackd.one/t.js" data-website="YOUR_WEBSITE_ID"></script>

It works on any website — static HTML, React, Vue, Next.js, WordPress, Shopify etc. For WordPress there is also a plugin that adds the script without code. Web Vitals are optional: with data-vitals="true" the script loads an additional module (≈ 1.5 KB).

<script type="module"> and tag managers: the script reads its configuration (data-website, data-host …) from document.currentScript. For a module script, or when a tag manager injects the script, currentScript is not set — the script then uses the first <script> tag on the page that carries a data-website attribute. So always put the data-* attributes on the script tag itself (in a tag manager: as attributes of the injected tag). Browsers load module scripts via CORS — /t.js is served with Access-Control-Allow-Origin: * for that.

Attributes

Attribute Meaning
data-website your website ID (required)
data-host points to your self-hosted instance instead of trackd.one
data-do-not-track="true" disables tracking on this page
data-heatmap="true" enables click collection for heatmaps
data-vitals="true" enables Web Vitals measurement (off by default)
data-vitals-sample="0.1" measures Web Vitals (with data-vitals="true") for a share of pageviews only (here 10%)

If your system cannot set data-* attributes (e.g. tag managers), pass the same settings as URL parameters without data-: https://trackd.one/t.js?website=YOUR-ID&vitals=true. Attributes take precedence. For Google Tag Manager there is a ready-made template.

Single-page apps

Client-side routing is detected automatically: history.pushState, replaceState, popstate and hashchange each create a pageview. Hash routers (#/path, #!/path) are treated like normal paths. Nothing else to set up.

  • Pageviews on route changes are sent with a ~300 ms delay so that the new page title is captured (the first pageview goes out immediately).
  • Only a change of path or hash route counts as a new pageview. A replaceState or pushState that changes query parameters only (e.g. ?tab=2) does not create another pageview — only the path and UTM parameters are stored anyway.

What is sent

Exactly one request per pageview to POST /api/collect:

{
  "type": "pageview",
  "website_id": "YOUR_WEBSITE_ID",
  "url": "https://example.com/pricing?utm_source=newsletter",
  "referrer": "https://www.google.com/",
  "title": "Pricing",
  "utm_source": "newsletter"
}
  • Query parameters with sensitive names (e.g. token, email, password) are removed before sending; email addresses in URLs are replaced with [email].
  • The script reads no device properties such as screen size or language (exception: heatmaps, opt-in only: window width); the server derives language and device type from request headers.
  • Of the URL only the path and the five UTM parameters (utm_source, utm_medium, utm_campaign, utm_term, utm_content) are stored, of the referrer only origin and path.
  • UTM values are stored trimmed and in lower case: Newsletter and newsletter count as one source. If the fields are missing from the request, trackd.one reads them from the page URL.

Domain check

Web requests must come from the registered domain or a subdomain (www. is ignored), otherwise the server answers 403. Events from localhost, 127.0.0.1 and *.local are not counted (unless the project’s domain itself is such an address) — use a separate test website if you want to measure staging environments.

Opt-out

The web script respects Global Privacy Control and “Do Not Track”: if either is set, it sends nothing and does not load the Web Vitals module. Your site can additionally turn tracking off via window.trackdOptOut = true or data-do-not-track="true". See Privacy & GDPR.

Ready in minutes

Start the 7-day free trial (no credit card), add your website or app, copy the snippet.

Start free trial