6 min read

Automatic Tracking

What TrimStats captures automatically out of the box, plus how referrers, Direct traffic ("dark social"), and UTM campaign tags work.

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

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 pageview whenever window.location.pathname changes.
  • 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 lightweight leave beacon with d (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 typeTrigger ruleStored event name (`n`)Properties (`p`)
outboundAnchor href hostname differs from window.location.hostnameDestination hostname (e.g. github.com){ "url": "https://github.com/..." }
downloadSame-origin anchor whose pathname ends with .pdf, .zip, .gz, .tar, .dmg, .exe, .csv, .xlsx, .docx, .pptx, .mp4, or .mp3File pathname (e.g. /files/guide.pdf){ "url": "https://yoursite.com/files/guide.pdf" }
Skipping specific links

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.

ParameterQuestion it answersExample values
utm_sourceWhich platform or publication sent the visit?newsletter, hackernews, google, partner_blog
utm_mediumWhat marketing channel type was used?email, cpc, social, referral
utm_campaignWhich specific launch or promotion?q4_launch, black_friday, spring_webinar
utm_contentWhich specific link or creative variant?hero_cta, footer_link, banner_v2
utm_termWhich paid search keyword triggered the ad?privacy+analytics, ga4+alternative
Site analytics / Overview / Acquisition & Pages
Switch tabs inside the Acquisition card to slice traffic by Referrers, UTM Source, Medium, Campaign, Term, or Content.

Common technical questions

How does TrimStats prevent internal navigation links from counting as outbound clicks?
The tracker compares each clicked anchor hostname against window.location.hostname and records an outbound event only for external domains, while stripping self-referrals automatically on the collector.
Can I exclude specific download links or outbound anchors from automatic tracking?
Yes. Add the data-trimstats-ignore attribute to any anchor element whose clicks should not emit automatic outbound or download events.

Related guides