Automatic Tracking
What TrimStats captures automatically out of the box, plus how referrers, Direct traffic ("dark social"), and UTM campaign tags work.
What user interactions does TrimStats track automatically without extra code?
Out of the box inside 1.96 KB gzipped, TrimStats automatically records pageviews, client-side SPA history.pushState and popstate transitions, visibility-aware active dwell time via leave beacons, outbound link clicks, common file downloads, clean external referrers, and all five UTM campaign parameters.
Pageviews & SPA navigation
On initial load, t.js sends a pageview beacon with the full URL, document.referrer, and any UTM query parameters. On single-page applications, t.js wraps window.history.pushState and subscribes to popstate.
- Route changes trigger a new
pageviewwheneverwindow.location.pathnamechanges. - Query-only or hash-only updates on the same pathname do not inflate pageview counts.
- Trailing slashes are normalized server-side (
/pricing/becomes/pricing, while/stays/). - Before recording the next SPA route, TrimStats flushes active engagement time for the previous route.
Visibility-aware engagement time
Instead of measuring wall-clock time between timestamps (which overcounts background tabs), TrimStats tracks active visible time using the browser Page Visibility API (document.visibilityState).
- The timer pauses immediately when a visitor switches tabs or minimizes the window.
- When the tab hides, the page unloads (
pagehide), or an SPA route transition occurs, TrimStats sends a lightweightleavebeacon withd(elapsed visible milliseconds) whenever at least 500 ms of visible time has accumulated. - Active engagement time feeds Visit time, Bounce rate (sessions under 10 seconds with 1 pageview), and per-page durations inside Visitor Timelines.
Outbound links & file downloads
A single passive document click listener inspects clicks inside <a href="..."> elements and automatically classifies external navigations and file downloads.
| Event type | Trigger rule | Stored event name (`n`) | Properties (`p`) |
|---|---|---|---|
outbound | Anchor href hostname differs from window.location.hostname | Destination hostname (e.g. github.com) | { "url": "https://github.com/..." } |
download | Same-origin anchor whose pathname ends with .pdf, .zip, .gz, .tar, .dmg, .exe, .csv, .xlsx, .docx, .pptx, .mp4, or .mp3 | File pathname (e.g. /files/guide.pdf) | { "url": "https://yoursite.com/files/guide.pdf" } |
Add the data-ts-ignore attribute to any <a> tag to skip automatic outbound or download tracking on that element: <a href="https://example.com" data-ts-ignore>Skip me</a>.
How referrers, Direct traffic, and UTM parameters work
When someone clicks a link from another website, browsers normally send that site domain in document.referrer. However, clicks from Slack, Discord, WhatsApp, native email clients, mobile apps, and bookmarks strip the referrer header completely, causing those visits to appear as Direct / None ("dark social").
Adding UTM query parameters to your campaign links solves dark social attribution cleanly. For example: https://acme.dev/pricing?utm_source=newsletter&utm_medium=email&utm_campaign=q4_launch. TrimStats parses all five standard UTM parameters automatically (up to 128 chars each) and strips self-referrals matching your own hostname.
| Parameter | Question it answers | Example values |
|---|---|---|
utm_source | Which platform or publication sent the visit? | newsletter, hackernews, google, partner_blog |
utm_medium | What marketing channel type was used? | email, cpc, social, referral |
utm_campaign | Which specific launch or promotion? | q4_launch, black_friday, spring_webinar |
utm_content | Which specific link or creative variant? | hero_cta, footer_link, banner_v2 |
utm_term | Which paid search keyword triggered the ad? | privacy+analytics, ga4+alternative |
Common technical questions
How does TrimStats prevent internal navigation links from counting as outbound clicks?
Can I exclude specific download links or outbound anchors from automatic tracking?
Related guides
Learn when to use custom events instead of pageviews, how to avoid event explosion with flat properties, and how to inspect property breakdowns.
Learn how visitors, sessions, bounce rate, and active dwell time work, plus how TrimStats calculates core KPIs and click-to-filter segments.
Exclude your own visits, restrict ingestion to approved hostnames, skip specific links, and see how TrimStats drops bots before billing.