Script Configuration
Complete reference for every HTML data attribute supported by t.js, including first-party mode, UI friction, and custom proxy endpoints.
Which HTML data attributes configure the TrimStats t.js tracker script?
TrimStats t.js supports four HTML data attributes on its script tag: required data-site (your pk_live_ site key), optional data-mode="first-party" (paired with the dashboard toggle for persistent IDs), optional data-friction="true" (opt-in rage/dead click and 90% scroll tracking), and optional data-api for custom reverse-proxy endpoints.
Supported script attributes
TrimStats reads its runtime configuration directly from data-* attributes on the <script> element (document.currentScript or the first script[data-site] node). No separate initialization call is needed.
data-sitestringRequiredYour site public tracking key (for example pk_live_9f3c...), available in Site settings. If omitted, t.js exits silently without sending any requests.
data-mode"first-party"OptionalDefault: cookielessOpt in to persistent first-party visitor IDs (_ts_vid) and attribution snapshots (_ts_attr) in localStorage. Must also be enabled in Site settings -> Identity mode.
data-friction"true"OptionalDefault: falseEnables lightweight DOM listeners for rage clicks, dead clicks, and 90% scroll reach. See UI Friction Tracking for exact thresholds.
data-apiURL stringOptionalDefault: <script origin>/v1/collectOverrides the POST beacon endpoint. Useful when proxying TrimStats through your own domain (for example https://acme.com/api/ts/collect).
Interactive snippet generator
<script
defer
src="https://collect.trimstats.com/t.js"
data-site="pk_live_your_key"
></script>Full-featured script example
Below is an example with first-party identity, UI friction signals, and a first-party reverse proxy enabled simultaneously.
1<script2 defer3 src="https://yourdomain.com/metrics/t.js"4 data-site="pk_live_your_key"5 data-mode="first-party"6 data-friction="true"7 data-api="https://yourdomain.com/metrics/v1/collect"8></script>Proxying through your own domain
You can serve t.js and proxy /v1/collect from your own subdomain or path using Next.js rewrites, Cloudflare Workers, or Nginx. Forward the visitor IP header (X-Forwarded-For or CF-Connecting-IP) and User-Agent so country detection and daily cookie-less hashing stay accurate.
1import type { NextConfig } from 'next';23const nextConfig: NextConfig = {4 async rewrites() {5 return [6 {7 source: '/ts/script.js',8 destination: 'https://collect.trimstats.com/t.js',9 },10 {11 source: '/ts/collect',12 destination: 'https://collect.trimstats.com/v1/collect',13 },14 ];15 },16};1718export default nextConfig;Common technical questions
Does setting data-mode="first-party" alone enable persistent visitor IDs?
How do I proxy TrimStats through my own first-party domain?
Related guides
Add TrimStats to any website in under 60 seconds with a single deferred script under 2 KB gzipped.
Choose per site between zero-storage cookie-less analytics and persistent first-party visitor IDs, plus optional logged-in user identification.
Learn what rage clicks, dead clicks, and deep scroll reach reveal about broken UX, and pinpoint exact offending CSS selectors with zero session-replay bloat.