Public Stats REST API & API Keys
Authenticate with workspace or single-site Bearer API keys to query overview KPIs, live visitors, revenue, funnels, cohorts, UI friction, insights, and AI traffic from the collector.
How do I query TrimStats analytics programmatically with API keys?
Create a read-only ts_live_ API key under Workspace -> API keys (workspace-wide or locked to one site) and send it in Authorization: Bearer to https://collect.trimstats.com/v1/sites and per-site endpoints for overview, live visitors, revenue, funnels, cohorts, UI friction, insights, and AI traffic.
Authentication & key scoping
Create read-only API keys (ts_live_...) under Workspace -> API keys (owners and admins only). Each key can access all sites in your workspace or be locked to a single site (following least-privilege scoping so an agency client dashboard or MCP bot only sees one domain). Only the SHA-256 hash is stored in Postgres; plaintext keys are displayed once on creation.
Send your key in the Authorization: Bearer header on every request to https://collect.trimstats.com/v1/.... Never place secrets in URL query parameters (?api_key=, ?token=, ?key=): URLs leak into reverse-proxy access logs, browser histories, and Referer headers, so TrimStats explicitly rejects query-string keys with 400 Bad Request.
1# 1. List sites accessible to this API key2curl -sS "https://collect.trimstats.com/v1/sites" \3 -H "Authorization: Bearer ts_live_your_api_key"45# 2. Query 7-day overview KPIs, timeseries, breakdowns, and goals6curl -sS "https://collect.trimstats.com/v1/sites/<site_id>/overview?from=2026-11-24&to=2026-11-30" \7 -H "Authorization: Bearer ts_live_your_api_key"Stats API endpoints intentionally omit permissive CORS headers and return Cache-Control: private, no-store. Call them from your backend, scheduled jobs, BI pipelines, or MCP tools so your ts_live_ key is never exposed in client-side browser bundles.
Available v1 endpoints
| Method & Path | Key Query Parameters | Returns |
|---|---|---|
GET /v1/sites | None | Sites accessible to the key (id, name, domain, trackingMode, frictionEnabled, timezone). |
GET /v1/sites/:siteId/overview | from, to, compare, country, device, browser, os, pathname, referrer, utmSource, utmMedium, utmCampaign, utmTerm, utmContent | KPIs, prior-period comparison, live count, timeseries, breakdowns, custom events, and goals. |
GET /v1/sites/:siteId/live | None | Real-time visitor count active in the last 5 minutes (liveVisitors). |
GET /v1/sites/:siteId/events/properties | eventName (required), from, to, plus overview segment filters | Top property keys and values for a custom event. |
GET /v1/sites/:siteId/revenue | from, to, attribution (first_touch or last_touch) | Attributed revenue totals, daily series, and referrer/UTM/landing-page/country breakdowns. |
GET /v1/sites/:siteId/insights | includeDetails (true or false) | Active rolling 7-day anomalies and optional daily trends, drivers, and 30-day history. |
GET /v1/sites/:siteId/friction | from, to | Rage clicks, dead clicks, 90% scroll reach, and top friction pages and CSS selectors. |
GET /v1/sites/:siteId/funnels | None | Saved funnel definitions (id, name, steps). |
GET /v1/sites/:siteId/funnels/:funnelId | from, to, windowSeconds | Step-by-step windowFunnel() conversion and drop-off report for a saved funnel. |
POST /v1/sites/:siteId/funnels/evaluate | JSON body: { from, to, windowSeconds, steps } | Ad-hoc 2 to 8 step funnel evaluation. |
GET /v1/sites/:siteId/cohorts | weeks (2 to 12, default 8) | Weekly retention cohort matrix for persistent visitors. |
GET /v1/sites/:siteId/ai-crawlers | from, to, category (ai_answers, indexing, training), crawler, pathname | AI crawler hit totals, breakdown, pages, and daily series. |
GET /v1/sites/:siteId/ai-referrals | from, to, provider, pathname | Human visits, revenue, goals, and #:~:text= cited passages from AI assistants. |
Rate limits & response headers
Requests are rate-limited atomically in Valkey at 60 requests/minute per API key and 120 requests/minute per workspace. Every authenticated response includes standard rate-limit headers:
| Header | Meaning |
|---|---|
X-RateLimit-Limit | Maximum requests permitted in the current 60-second window. |
X-RateLimit-Remaining | Remaining requests available before throttling. |
X-RateLimit-Reset | Seconds until the current rate-limit window resets. |
Retry-After | Included on 429 Too Many Requests responses indicating seconds to wait. |
401 Unauthorized: Missing, malformed, expired, or revokedAuthorization: Bearertoken.403 Forbidden: Workspace does not have an active subscription.404 Not Found: Site or funnel does not exist or is outside the API key scope.429 Too Many Requests: Key/workspace rate limit or repeated invalid auth threshold exceeded.
Common technical questions
What rate limits apply to the TrimStats Stats REST API?
Can I restrict a TrimStats API key to a single website?
Related guides
HTTP specification for POST /v1/collect, payload validation rules, rate/quota responses, and server-side event ingestion.
Learn how visitors, sessions, bounce rate, and active dwell time work, plus how TrimStats calculates core KPIs and click-to-filter segments.
How TrimStats detects traffic drops, spikes, conversion dips, and friction surges against rolling 7-day baselines and delivers alerts and digests to email, Slack, Discord, and HMAC-signed webhooks.