4 min read

Script Configuration

Complete reference for every HTML data attribute supported by t.js, including first-party mode, UI friction, and custom proxy endpoints.

Imtiaz Rayhan
Imtiaz RayhanCo-Founder & Lead Engineer, DotCamp & TrimStats
Verified against live TrimStats APIs
Quick reference

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.

Site settings / Tracking snippet
The snippet card under Site settings automatically mirrors your site public key, identity mode, and UI friction toggles.
data-sitestringRequired

Your 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: cookieless

Opt 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: false

Enables 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/collect

Overrides the POST beacon endpoint. Useful when proxying TrimStats through your own domain (for example https://acme.com/api/ts/collect).

Interactive snippet generator

Interactive Snippet Builder
Customize your tracker attributes and copy a production-ready tag.
Cookie-less · No banner
<script
  defer
  src="https://collect.trimstats.com/t.js"
  data-site="pk_live_your_key"
></script>
Remember to enable matching toggles under Site settings so the collector accepts first-party IDs.

Full-featured script example

Below is an example with first-party identity, UI friction signals, and a first-party reverse proxy enabled simultaneously.

index.htmlhtml
1<script
2 defer
3 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.

next.config.tsts
1import type { NextConfig } from 'next';
2
3const 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};
17
18export default nextConfig;

Common technical questions

Does setting data-mode="first-party" alone enable persistent visitor IDs?
No. Persistent first-party mode is dual-gated for safety: you must both enable First-Party ID mode in TrimStats Site settings and include data-mode="first-party" on the script tag, otherwise the collector stays strictly cookie-less.
How do I proxy TrimStats through my own first-party domain?
Proxy /t.js and /v1/collect on your reverse proxy (such as Cloudflare, Caddy, or Next.js rewrites) to collect.trimstats.com and set data-api="https://yourdomain.com/v1/collect" on the script tag.

Related guides