HTTP API
The collect event contract, its guards and limits, and every route under /api/marketing with its access level.
All routes live under /api/marketing. The public routes serve tracked sites. Every other route needs a DMS JWT.
Event contract
POST /api/marketing/collect is public and takes batches of 1 to 25 events, validated with zod. It answers { accepted, dropped }.
Guards
The endpoint is public, and these checks run in order before any event is stored:
- Collection switch. While collection is paused in Settings, every batch answers 200 with all events counted as
dropped. - Website. An unknown website ID, or a site whose own tracking switch is off, answers 404.
- Browser origin. The
Originhostname, or theRefererhostname whenOriginis absent, must be the website'sdomain, a subdomain of it, or one of itsextraDomains. Any other host answers 403, including the literalnullthat sandboxed frames send. Page script cannot set these headers, so a tracker copied onto a foreign site reports that site and is refused. A request with neither header is dropped silently. Every browser setsOriginon a POST, so only hand-made clients send none. - Declared automation. Crawlers, CLIs, HTTP libraries, fetchers and headless engines that announce themselves (the
ua-parser-jslists), and requests with no user agent, answer 200 with all events counted asdropped. - Per-source rate. A fixed one-minute window allows 600 events per website and IP, in memory on each instance. The budget is an order of magnitude above a heavy visitor, so carrier-grade NAT does not trip it. A refusal answers 200 with all events counted as
dropped.
The IP is the one the DMS resolves with getClientIp from @antelopejs/interface-dms/client-ip. X-Forwarded-For is read only behind the reverse proxies that the DMS trusts (auth.trustedProxies), at the entry the outermost trusted proxy appended. Entries to the left of it are client claims, which could create a visitor, avoid the rate budget or spend another visitor's budget.
A refused host is remembered for the install guide's Allow this host action only when it looks like a browser's: a valid hostname, from a request that carries Sec-Fetch-Mode. The memory keeps up to 5 hosts per website for an hour.
The guards do not stop a scripted client that forges a browser user agent and a matching Origin. No public analytics product authenticates its ingestion. The remedy for such data is detection and the per-site purge (POST /websites/:id/purge).
Request body
@RawBody reads the body under MAX_COLLECT_BODY_BYTES (256 KiB) and answers 413 past it. The body must be JSON, whatever its content type, or the request answers 400. Only the envelope, a website ID and 1 to 25 events, can fail the request with a 400.
Each event is then validated on its own. A failing event is dropped and counted in dropped, and the rest of its batch is kept. The module logs drops once a minute per site. An event fails when:
- its
urlis neither anhttporhttpsURL nor a path - its
nameis missing where required, or longer than 50 characters (64 for the experiment key of anexposure) - its
datadoes not match its kind's shape, or a custom event'sdatais over 4,096 characters of serialized JSON
Context text is cut to its cap instead of failing: url and referrer at 500 characters, title at 200, and screen and language at 16.
{
"website": "<website id>",
"events": [
{
"kind": "pageview | custom | exposure | click | scroll",
"url": "https://example.com/pricing?utm_source=newsletter",
"referrer": "https://example.org/", // optional
"title": "Pricing", // optional
"screen": "1920x1080", // optional
"language": "fr-FR", // optional
"name": "signup_submitted", // required for custom (event name) and exposure (experiment key)
"data": { "plan": "pro" }, // kind-specific, at most 4,096 characters of JSON for custom
"at": 1754500000000 // optional client ms, ignored past 5 minutes of skew
}
]
}
Event data by kind
| Kind | data payload |
|---|---|
click | {x, y, dx, dy, selector, ox, oy, nth}. x and y are required and viewport-normalized (where on the screen). dx and dy are document-normalized. selector, ox, oy and nth are the element anchor that heatmaps project from: the nearest short CSS path (at most 120 characters), the offset inside that element's box, and the element's index among the selector's matches. x, y, dx and dy are fallbacks, see Heatmap anchoring. Every fraction lies in 0 to 1. |
pageview | {sample}, optional. The heatmap sampling rate (0 to 1) that the tracker applied to the view. Pages and heatmaps reports "recorded on N % of page loads" as the average of these declared rates. Counting scroll events against pageviews would undercount views left before their depth is sent. Any other payload is dropped and the pageview kept. |
scroll | {depth}, the maximum percentage of the page reached, an integer from 0 to 100. Every sampled view sends one, 0 when it never scrolled. |
exposure | {experiment, variation}, each at most 64 characters, the arm that the page applied. name carries the experiment key. Nothing re-derives the arm, so the page's claim stands. The key is checked. An exposure for anything but a running split is dropped at ingestion, see Assignment contract. |
HTTP surface
Public routes
| Route | Purpose |
|---|---|
POST /collect | Event ingestion, see Event contract. Answers {accepted, dropped}. |
GET /tracker.js | The first-party tracker script, cached for an hour. While collection is paused it publishes only a no-op window.dmsMarketing, cached for a minute, so page code keeps working. |
GET /experiments.js?website= | The per-visitor assignment script for the site's funnels whose A/B split is running, see Assignment contract. |
GET /snapshot.js?website=&path=&width= | Snapshot negotiation. The capture script when the backend wants a snapshot of that path at that viewport width, an empty script otherwise, see Snapshot contract. |
POST /snapshot | Snapshot upload. One serialized page rendering, capped and rate-limited, accepted only with the token its negotiation handed out. |
The module declares these five routes to the DMS as its publicEndpoints (src/routes/public-endpoints.ts). The install guide's snippet points at the dashboard's origin, and the DMS frontend server lets a tracked site's scripts and beacons through without a session only for declared routes.
Websites
| Route | Auth | Purpose |
|---|---|---|
GET /websites | tenant member | The tenant's websites, most recently active first, so a dashboard that opens the first entry opens one with data. |
POST /websites, PUT /websites/:id | tenant owner | Create or update a website. snapshotsEnabled and snapshotMaskText are the page-snapshot opt-in and masking options. Changing either discards the site's snapshots. Changing snapshotsEnabled sets snapshotsSetBy: "owner", which configuration never overrides. |
DELETE /websites/:id | tenant owner | Deletes the site and purges its tracking data, see Website deletion and purge. Answers 409 for the dashboard's own site (dashboardTracking), which is never deleted. |
GET /websites/:id/deletion | tenant owner | Counts what a delete or a purge discards. |
POST /websites/:id/purge | tenant owner | Body { scope: "heatmaps" | "all" }, required (400 without it). heatmaps deletes the site's clicks, scroll depths and page snapshots. all deletes everything it collected: events, sessions, rollups, snapshots and applied imports. Keeps the site, its settings and its funnels. Works on any site, the dashboard's own included, and is idempotent. Answers { purged, scope, deleted: { events, sessions, days, snapshots, imports } } and publishes on marketing.websites. |
GET /websites/:id/connection | tenant member | The install guide's check: the site's state, its most recent visit (URL, browser and device) and its recently refused hosts. |
POST /websites/:id/allow-host | tenant owner | Adds a refused host to the site's extraDomains and forgets its refusals. |
POST /dashboard-tracking | tenant member | With dashboardTracking on, the website that the dashboard's own tag reports to, { websiteId }. Created for the caller's tenant on the first call, with an ID derived from the tenant and snapshots per dashboardTracking.snapshots until an owner changes them. snapshotsSetBy records whether config or the owner set them. The request's Origin host (else Referer) is added to the site's extraDomains when it is new. When dashboardTracking.snapshots changes the switch of an existing site that no owner has set, the call discards that site's snapshots. 404 while the option is off, 400 without a usable host. |
Context and blocks
| Route | Auth | Purpose |
|---|---|---|
GET /context, PUT /context | tenant member | The context bar: the tenant's websites with their live state and the caller's selection. PUT {website} stores the selection, see Context and period. |
GET /blocks/kpi?metric= | tenant member | One KpiCard: pageviews, sessions, new-visitors or custom-events, with its change and sparkline. |
GET /blocks/traffic?metric= | tenant member | The traffic ChartCard, with the comparison window as a second series. |
GET /blocks/quality | tenant member | Bounce rate, average session duration and pages per session, with their change. |
GET /blocks/devices | tenant member | The devices TopListCard. |
GET /blocks/tops?group= | tenant member | One tabbed top-list card: content, acquisition, audience or events (goal events flagged). |
GET /blocks/top?dimension=&limit= | tenant member | One TopListCard over a rollup dimension, such as referrers or UTM contents and terms. limit defaults to 5, at most 50. |
GET /blocks/channels | tenant member | Sessions per channel, with share and change. |
GET /blocks/campaigns/rows?search=&filter_channel=is:<channel> | tenant member | The UTM campaign table (TableView.fromSource), { results, total }, paged. Per (source, medium, campaign, channel) key: share, daily sessions, derived channel and the missing-medium flag. |
GET /blocks/campaigns/notice?kind=tagged|missing | tenant member | The notice beside the campaign table, for a stock Banner: the share of sessions tagged, or the sessions tagged without a medium. null when there is none. |
GET /blocks/collection-notice | tenant member | The "collection paused" notice over the Websites grid and in the install guide, for a stock Banner. null while the module collects. |
GET /blocks/website-notice | tenant member | The notice over an analytics page while its website has sent nothing yet, linking to the install guide, for a stock Banner. null in every other state, so once the first event arrived, and also for a paused or an imported-only site. |
Statistics
| Route | Auth | Purpose |
|---|---|---|
GET /stats/overview?website=&from=&to= | tenant member | The dashboard read, from rollups. |
GET /stats/pages?website=&from=&to=&search=&limit=&sort=&workspace= | tenant member | The inventory of observed paths, { pages, total, truncated, sampleRate, trackerEnabled, snapshotsEnabled }, so the caller can explain an empty heatmap. limit defaults to 100 and is capped at 200. sort=clicks orders by clicks, anything else by views. workspace lets a platform owner read another workspace's dashboard site, or every workspace's with all. |
GET /stats/heatmap?website=&path=&from=&to= | tenant member | The click heatmap, also served through the interface. website is optional and merges the tenant's sites when omitted, so pass it. |
GET /stats/scroll?website=&path=&from=&to= | tenant member | The scroll-depth distribution of one path, with the same window, sampling and website rule as the clicks. |
GET /stats/snapshot?website=&path=&layout= | tenant member | The page snapshot that the heatmap is drawn over: the capture at that layout, else the nearest one (exact: false), else null. layout is desktop, tablet or phone, and desktop when absent or empty. Any other value, Desktop included, answers 400. A document always wins over a row that records an oversize capture, which comes back as html: null with the bytes it reached. |
GET /stats/workspaces?website= | tenant member | The workspace selector of the Pages view, read with the page (server render included) so the panel never grows after the first paint. The DMS core tenants that have a dashboard website, the caller's first. Only for a platform owner on their own dashboard website, and only with two or more. [] otherwise. |
/stats/pages, /stats/heatmap, /stats/scroll, /stats/snapshot with &workspace=<tenantId>|all | platform owner | The same reads for another workspace's dashboard website, or every workspace's. Each read runs in its own tenant, then the results merge: cells re-keyed by anchor or grid cell, counts summed, and the sampling share over all declared pageviews. 404 for anyone else, or from a customer website. The snapshot is the newest capture in the scope, with its text masked server-side (masked: true). |
GET /stats/heatmap/count?website=&path= | tenant owner | What the reset below would delete, {events, snapshots} over every period, for its confirmation dialog. |
DELETE /stats/heatmap?website=&path= | tenant owner | Heatmap reset. Deletes the clicks, scroll depths and snapshots of one path, or of the whole site without path. website is required. Answers {events, snapshots} deleted. The dashboard purges a whole site through POST /websites/:id/purge. |
Funnels
| Route | Auth | Purpose |
|---|---|---|
GET /funnels/rows?filter_kind=is:funnel|ab | tenant member | The funnels table (TableView.fromSource), { results, total }. Per funnel: sessions entered, conversion and its change in points, or the A/B test's state. |
GET /funnels/winner | tenant member | The banner above the funnels table, for a stock Banner. In order: the days of the period that raw events do not cover, else the running test ready to decide (significant, leader ahead, 7 days served, 50 conversions per arm), else a comparison left out. null otherwise. |
GET /funnels/templates?website= | tenant member | First-run templates from the period's raw journeys: the top custom events, each led by the page viewed most often before it, with the sessions that would enter. |
GET /funnels/:id/delete-confirmation | tenant member | The list's delete dialog worded for the row. A running test says that it stops. |
GET /funnels/suggestions | tenant member | The site's top pages and custom events of the last 30 days, for the builder's autocomplete. |
POST /funnels/preview | tenant member | Scores unsaved steps and a window over the last 30 days, for the builder. |
GET /funnels/:id/results | tenant member | The funnel computed at read time. Each step lists the events it matches, 0 for a step never sent. previous is the same computation over the comparison window, for plain funnels and drafts, and only when raw events cover it (coverage says what they cover). When the funnel carries an A/B split, the per-arm read uses the same steps over the split's runs: exposed sessions, conversion, z-test verdicts with the lift interval (Bonferroni past two arms), the SRM check, decision (days served, ready) and verdict. verdict is the one reading that the report, its stop dialog and the list share: kind (winner, loser, flat, early or withheld) and the leader arm it names. |
Data controllers and settings
| Route | Auth | Purpose |
|---|---|---|
/tables/funnels/* | platform owner | The funnels DataController (TableView CRUD, scoped to the tenant instance with @TenantScopedModel). It enforces the split's draft → running ⇄ stopped lifecycle, stamps the runs it produces, and freezes the key and variations outside draft. |
/tables/websites/* | platform owner | The read-only websites DataController behind the Websites page's table and the relation pickers. Global table, scoped by column. list and get answer each row with its card: state, sessions, pages and funnels over 30 days, accepted hosts, snapshot and sampling state, and recently refused hosts. The /websites writes publish on marketing.websites, the table's realtimeTopic. |
GET /settings, PUT /settings | platform owner | The settings form. PUT merges a partial body: a key left out keeps its value, and null or the default itself resets it to the config default. It refuses with 400, with the issue under the field, a snapshot retention longer than the raw-event retention or a statistics retention shorter than it. It answers 409 to the first save of a retention cut that deletes data, and saving again confirms. |
GET /settings/collection, POST /settings/collection | platform owner | The master switch, the websites and their 30-day sessions. POST {enabled} flips the switch. |
GET /settings/collection/banner | platform owner | The Collection section, for a stock Banner: state, coverage, and the pause (confirmed) or resume action. |
GET /settings/glance?item= | platform owner | One Meter of At a glance: raw, statistics or snapshots retention, on a shared scale. |
Period parameters
The tenant-member routes under /blocks, /stats, /funnels/rows, /funnels/winner, /funnels/templates and /funnels/:id/results read their window from the period scope, see Context and period. Without from and to, they read the last 7 days.
Cross-origin requests
Tracked sites need no CORS grant. The tracker posts text/plain, a CORS-safelisted type that sends no preflight. The backend parses the JSON body whatever its content type, and gates on the Origin header that the browser sets instead. The assignment read keeps the same property the other way round. It is a script that the page loads with <script src>, not JSON that a page would need CORS to read. The @antelopejs/api CORS configuration matters only for the authenticated console origins.