Key concept6 min read

Dual-Mode Identity & User Identification

Choose per site between zero-storage cookie-less analytics and persistent first-party visitor IDs, plus optional logged-in user identification.

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

How does TrimStats dual-mode visitor identity work?

Every TrimStats site defaults to strictly cookie-less mode (zero cookies, zero localStorage, 24-hour rotating 32-byte SHA-256 daily salts). When you need multi-week retention cohorts, 30-day funnels, or 90-day timelines, you can explicitly opt in per site to First-Party ID mode (_ts_vid, _ts_attr) or call identify(userId) for logged-in users.

Cookie-less vs First-party ID

Analytics tools face a real trade-off between zero browser storage and multi-day memory. In cookie-less mode, rotating the hashing salt every midnight UTC mathematically erases the link between yesterday and today: great for zero-banner privacy, which also means the same person returning 5 days later looks like a brand-new visitor.

Every site in TrimStats defaults to Cookie-less mode, requiring zero browser storage and zero consent banners. Whenever a site needs multi-day visitor timelines, weekly retention cohorts, 30-day funnels, or 90-day revenue attribution, opt in to First-party ID mode on a per-site basis.

CapabilityCookie-less (Default)First-party ID (`first-party`)Identified (`identify()`)
Browser storageNone (zero cookies, zero localStorage)_ts_vid + _ts_attr in localStorageIn-memory uid (plus _ts_vid if first-party)
Consent banner typically required?NoDepends on jurisdiction (ePrivacy / GDPR)Depends on your logged-in privacy notice
Unique visitors & sessionsSame UTC dayCross-day on same browserCross-day & cross-device
FunnelsWithin same dayUp to 30-day windowUp to 30-day window across devices
Weekly retention cohortsExcluded from cohortsFull 2 to 12 week cohortsFull 2 to 12 week cohorts
Revenue attribution lookbackSame-day or metadata fallbackFull 90-day ClickHouse lookback90-day lookback by user ID

How visitor IDs are derived server-side

The collector resolves every incoming beacon to an opaque 64-bit unsigned integer (visitor_id) using SHA-256 in the following strict priority order:

  1. Identified (`identified`): If uid was passed via window.trimstats('identify', userId), the collector hashes uid:{siteId}:{externalUserId}.
  2. First-party (`first_party`): If the site has First-party ID enabled in Site settings AND the script sent a client vid, the collector hashes fp:{siteId}:{clientVid}.
  3. Cookie-less (`cookieless`): Otherwise, the collector fetches a 32-byte random salt rotated every UTC day (salt:YYYY-MM-DD) and hashes cl:{dailySalt}:{siteId}:{clientIp}:{userAgent}. Once the UTC day passes and the salt expires, old hashes can never be linked back to a person or IP.

Enabling first-party mode

Site settings / General & Privacy
First-party identity is dual-gated for safety: toggle First-party ID here AND include data-mode="first-party" on your <script> tag.
  1. 1

    Enable First-party ID in Site settings

    Open your site, navigate to Site settings -> General & Privacy, select First-party ID, and click Save changes.

  2. 2

    Add data-mode="first-party" to your script tag

    Update your <script> tag to include data-mode="first-party". The tracker will generate a random UUID in localStorage._ts_vid and save the visitor first-touch attribution snapshot in localStorage._ts_attr.

    HTML
    <script defer src="https://collect.trimstats.com/t.js" data-site="pk_live_your_key" data-mode="first-party"></script>
Consent-gated activation

If your site displays a cookie or analytics consent banner before enabling first-party mode, render data-mode="first-party" only after the user opts in, or keep the default cookie-less snippet without data-mode for visitors who decline.

Identifying logged-in users

For SaaS applications with authenticated accounts, call window.trimstats?.('identify', userId) after login or session hydration. Pass an opaque database UUID or customer ID (up to 128 characters), not a raw email address.

auth-session.tsts
1// Call after authentication succeeds
2if (session?.user?.id) {
3 window.trimstats?.('identify', session.user.id);
4}
5
6// Subsequent events and window.trimstats.attribution() now carry uid
7window.trimstats?.('event', 'workspace_created', { teamSize: 4 });

Passing the same userId as client_reference_id (Stripe) or inside metadata.uid (Paddle, Polar, or Custom webhooks) lets TrimStats attribute subscription renewals and cross-device upgrades back to the exact acquisition source.

Site analytics / Visitors & Timeline
Calling identify() elevates a visitor badge to Identified, linking return visits, custom event properties, and server-verified Stripe payments into a single timeline.

Common technical questions

What is the server-side priority order between identify(), first-party ID, and cookie-less?
When enabled, TrimStats resolves identity in deterministic priority: explicit external user ID from identify() first (up to 128 chars), opt-in first-party _ts_vid second, and daily salted SHA-256 cookie-less hash as the zero-storage fallback.
Can I keep my marketing site cookie-less while using First-Party ID inside my SaaS app?
Yes. Identity mode is configured independently per site key, so public marketing pages stay strictly cookie-less with no consent banner while authenticated product routes use persistent IDs or opaque user UUIDs.

Related guides