REST API reference
Query your stats, send server-side events and erase users over HTTP.
Authentication
The API is included from the Growth plan. Create an API key under Account → API keys and send it as a Bearer token. A key acts as the user who created it: it can read every site that user can view, and write (send events, erase users) on sites where the user is an owner or admin.
curl "https://stancelens.com/api/v1/stats/aggregate?site_id=SITE_ID&period=30d" \
-H "Authorization: Bearer $STANCELENS_API_KEY"| Base URL | https://stancelens.com/api/v1 |
| Format | JSON in, JSON out. Timestamps you send are epoch milliseconds; dates in responses are ISO 8601. |
| Errors | { "error": "message", "code": "…" } with 400 (bad request, e.g. missing_site_id or invalid_param), 401 (unauthorized), 402 (plan_upgrade_required: the site's plan doesn't include this, or subscription_inactive; the body adds upgrade_url, and feature and required_plan when a plan is missing), 403 (forbidden: the key can't read the site, or can't write to it), 429 (rate_limited) or 500 (internal, an unexpected server error; safe to retry). |
| Rate limits | Per key: bursts of 120 requests, then 10 per second. Reads are also limited per key by the site's plan: 60 a minute on Growth, 300 on Pro and 600 on Business (the REST API isn't on Starter). POST /api/v1/events also allows 5,000 events in a burst, then 500 per second, per key and site. A 429 carries Retry-After (seconds). |
Sites
Every site the key can read, with your role (owner, admin or viewer). Writes need owner or admin.
{
"sites": [
{
"id": "example-com",
"domain": "example.com",
"name": "Example",
"timezone": "UTC",
"currency": "USD",
"role": "owner",
"public": false,
"created_at": "2026-11-21T00:00:00.000Z"
}
],
"user": { "id": "u_…", "email": "you@example.com" }
}One site, as { "site": { … } }. 403 when the key can't read it, including for IDs that don't exist.
Common query parameters
Every stats endpoint takes site_id plus the same parameters as the dashboard URL, so a dashboard URL's query string gives the same numbers through the API.
| Parameter | Values |
|---|---|
period | today, yesterday, 24h, 7d, 30d (default), mtd (month to date), lastmonth, 90d, 6mo, 12mo, ytd, all, custom. 7d, 30d and the others ending in days include today. |
from, to | YYYY-MM-DD, inclusive. Used when period=custom. |
timezone | IANA name such as Europe/Berlin. Defaults to the site's timezone (Site settings → General). An unknown name is a 400. |
compare | previous (default), year or off. |
interval | minute, hour, day, week, month. Defaults to a sensible value for the period. |
f_<dimension> | Filter, comma-separated values. Prefix ! to negate, ~ for contains. e.g. f_country=US,DE, f_path=~/blog, f_browser=!Safari. |
Days, weeks, months and custom dates are calendar days in the reporting timezone, the same as in the dashboard: today starts at local midnight and mtd on the 1st of the month, local time. On a daylight saving change a local day is 23 or 25 hours long. 24h is the last 24 hours, whatever the timezone.
Filter dimensions: path, hostname, entry_path, exit_path, referrer_domain, channel, utm_source, utm_medium, utm_campaign, utm_term, utm_content, country, region, city, browser, os, device, language, platform, app_version, device_model, os_version, sdk, name (event name), user_id.
Each stats response echoes the parsed query (period, from, to, interval, timezone, compare, the comparison range and filters) under query, so you can see exactly which range was used. from and to are UTC instants: in Europe/Berlin in winter, a day starts at 23:00:00.000Z the evening before.
Aggregate
Totals for the period, with the comparison period alongside. Optional metrics: any of visitors, visits, pageviews, views_per_visit, bounce_rate, visit_duration, events, revenue (default: all).
curl "https://stancelens.com/api/v1/stats/aggregate?site_id=SITE_ID&period=7d&metrics=visitors,bounce_rate,visit_duration" \
-H "Authorization: Bearer $STANCELENS_API_KEY"{
"site_id": "SITE_ID",
"query": {
"period": "7d",
"from": "2026-11-17T00:00:00.000Z",
"to": "2026-11-23T21:28:58.495Z",
"interval": "day",
"timezone": "UTC",
"compare": "previous",
"comparison": { "from": "2026-11-10T00:00:00.000Z", "to": "2026-11-16T21:28:58.495Z" },
"filters": []
},
"results": {
"visitors": { "value": 13524, "previous": 13378, "change": 1.1 },
"bounce_rate": { "value": 48.7, "previous": 49.5, "change": -1.6 },
"visit_duration": { "value": 104, "previous": 102, "change": 2 }
}
}changeis the percentage change, ornullwhen the previous value is 0. Withcompare=off, onlyvalueis returned.bounce_rateis a percentage;visit_durationis the average visit length in seconds.eventscounts custom events, excluding page views and internal events ($web_vital,$exposure,$identify).
Timeseries
Metrics per interval bucket. Every bucket in the range is returned, including empty ones. Day, week and month buckets start at local midnight in the reporting timezone; date and t give that start as a UTC instant.
{
"site_id": "SITE_ID",
"query": { "period": "7d", "interval": "day", "...": "..." },
"results": [
{
"date": "2026-11-17T00:00:00.000Z",
"t": 1794873600000,
"visitors": 2287,
"visits": 2354,
"pageviews": 5548,
"bounce_rate": 48.1,
"revenue": 4174
}
]
}Breakdown
Top values of one property, sorted by visitors. Params: property, limit (default 50, max 1000) and page (from 1).
property is any filter dimension above, screen, or props.<key> for a custom event property (props.plan). Visit-level properties (sources, UTM source/medium/campaign, entry and exit pages, location, device, browser, OS, language, platform, app_version, device_model) return visitors, visits, pageviews, bounce_rate and revenue. Event-level properties (path, hostname, name, utm_term, utm_content, screen, user_id, os_version, sdk, props.*) return visitors, visits, events and revenue; for path and hostname, events counts page views.
curl "https://stancelens.com/api/v1/stats/breakdown?site_id=SITE_ID&property=referrer_domain&limit=2" \
-H "Authorization: Bearer $STANCELENS_API_KEY"{
"site_id": "SITE_ID",
"property": "referrer_domain",
"query": { "period": "30d", "...": "..." },
"page": 1,
"limit": 2,
"results": [
{ "value": null, "visitors": 19566, "visits": 24867, "pageviews": 63973, "bounce_rate": 43.9, "revenue": 47277 },
{ "value": "google.com", "visitors": 15507, "visits": 15777, "pageviews": 34105, "bounce_rate": 53.7, "revenue": 1757 }
]
}A null value groups hits without that property (here: direct visits).
Realtime
visitors active in the last 5 minutes, plus visitors, page views, a per-minute series and the top 10 pages, referrers and countries for the last 30 minutes.
{
"site_id": "SITE_ID",
"visitors": 12,
"visitors_30m": 49,
"pageviews_30m": 91,
"per_minute": [{ "t": 1795467480000, "pageviews": 1, "visitors": 1 }],
"pages": [{ "value": "/pricing", "visitors": 9 }],
"referrers": [{ "value": "google.com", "visitors": 14 }],
"countries": [{ "value": "US", "visitors": 20 }]
}Send events
Record one event, or up to 100 in an array, from your server. The key needs owner or admin access to the site.
curl -X POST https://stancelens.com/api/v1/events \
-H "Authorization: Bearer $STANCELENS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"site_id": "SITE_ID",
"name": "invoice_paid",
"url": "https://app.example.com/billing",
"uid": "user_8231",
"props": { "revenue": 99, "currency": "USD" },
"ts": 1763683200000
}'| Field | Description |
|---|---|
site_id | Required in the body or as ?site_id=. Every event in a batch must use the same site. |
name | Event name. Defaults to pageview. |
url or path | Page URL or path the event belongs to. |
uid | Your user ID. Attributes the event to that user's profile, as identify does in the browser. |
vid | A stable anonymous ID for the visitor. Without vid or uid, server events from different end users can't be told apart. |
props | Object of properties. A numeric revenue (with optional currency) is counted as revenue. |
revenue | Alternatively a number or { amount, currency }. |
ts | Epoch ms when it happened. Defaults to now. Up to 30 days in the past; older events are dropped (ts_too_old). Up to 5 minutes ahead is clamped to now; later is dropped (ts_in_future). |
id | Your event ID. A retry with an ID already received for the site in the last 24 hours is dropped as duplicate. |
platform | Defaults to server, or web when you pass ua. Also accepted: app_version, os, os_version, device_model, device_type, sdk, session_id. |
ua, ip | Optional end-user user agent and IP, for device and visitor hashing. The IP isn't stored, and country isn't looked up from it. |
country | Optional ISO 3166-1 alpha-2 code of the end user's country (DE, US), when you know it. Without it, country is estimated from timezone, then from the region in language. |
Other fields of the ingest payload (referrer, title, language, timezone, screen, duration, traits) are accepted too. The response is 202 with one result per event, and sid, the session of the first accepted event:
{
"accepted": 1,
"dropped": 0,
"sid": "mwshxy004ac0de4e0f6c",
"results": [{ "ok": true, "session_id": "mwshxy004ac0de4e0f6c" }]
}A dropped event has { "ok": false, "reason": "…" }, where reason is one of invalid (with issues naming the fields), unknown_site, bot, excluded_ip, excluded_path, disabled (that event type is switched off under Site settings → Collection), no_session, duplicate, too_large, ts_too_old or ts_in_future. Hostname and localhost rules are skipped for events sent with an API key. If every event in the request is invalid the response is 400 invalid_payload with details; if every event names an unknown site, 404 unknown_site. Each event is checked on its own, so one bad or oversized event doesn't sink the batch: it's dropped with its reason (too_large for an event over 64 KiB of JSON) and the others are accepted. More than 100 events is 413 batch_too_large, and a request body over 1 MB is 413 payload_too_large.
Export raw events
Every event in the period, with filters applied, as CSV (default), a JSON array (format=json) or NDJSON, one JSON object per line (format=ndjson). See Data export.
Erase a user
Permanently deletes an identified user's events, sessions, profile and replays on one site, including the anonymous visits linked to them. Needs owner or admin access.
curl -X DELETE "https://stancelens.com/api/v1/users/user_8231?site_id=SITE_ID" \
-H "Authorization: Bearer $STANCELENS_API_KEY"{
"site_id": "SITE_ID",
"user_id": "user_8231",
"deleted": { "events": 412, "sessions": 37, "profiles": 2, "replays": 5 }
}Examples without an SDK
const res = await fetch(
"https://stancelens.com/api/v1/stats/aggregate?site_id=SITE_ID&period=30d",
{ headers: { Authorization: `Bearer ${process.env.STANCELENS_API_KEY}` } },
);
const { results } = await res.json();
console.log(results.visitors.value);import os, requests
r = requests.get(
"https://stancelens.com/api/v1/stats/breakdown",
params={"site_id": "SITE_ID", "property": "country", "period": "30d", "limit": 5},
headers={"Authorization": f"Bearer {os.environ['STANCELENS_API_KEY']}"},
)
print(r.json()["results"])