POST /api/event
Ingests a single analytics event. The server assigns a UUID and a UTC timestamp before persisting the record. Any string property values longer than 200 characters are silently truncated to 200 characters followed by....
The Iris SDK sends events using
navigator.sendBeacon when available (fire-and-forget, survives page unloads). It falls back to fetch with keepalive: true. You can call this endpoint directly if you need server-side or non-browser tracking.Request body
The body must be a JSON object matching theEventPayload shape. Keys are intentionally short to minimise wire size.
Event name. Built-in events use a
$ prefix (e.g. $pageview, $click, $web_vital). Custom events can be any string.Full URL of the page where the event occurred (e.g.
https://example.com/pricing).Domain (hostname) the event belongs to (e.g.
example.com). This is the primary multi-tenancy axis for all read queries.Referrer URL, or
null if there is none. Used by /api/referrers.Visitor’s viewport width in pixels (
window.innerWidth). Used by /api/devices to bucket into Mobile / Tablet / Desktop.Site ID configured in
IrisConfig.siteId. Stored for future multi-site use.Session ID — a UUID stored in
sessionStorage (iris_sid). Unique per browser tab; cleared when the tab closes.Visitor ID — a UUID stored in
localStorage (iris_vid). Persists across sessions on the same browser. No cookies are used.Optional map of custom properties (
Record<string, any>). String values longer than 200 characters are truncated server-side. Used to carry web vital metrics ($name, $val, $rating) and autocapture click metadata ($tag, $id, $class, $text, $href).Server-assigned fields
The following fields are never sent by the client — the server generates them:| Field | Type | Value |
|---|---|---|
id | string | UUID v4 generated via google/uuid |
ts | string | UTC timestamp at time of ingestion (time.Now().UTC()) |
Response
Returns202 Accepted with an empty body on success.
| Status | Meaning |
|---|---|
202 Accepted | Event saved successfully |
400 Bad Request | Request body is not valid JSON |
500 Internal Server Error | Database write failed |
EventPayload JSON shape
Examples
POST /api/events
Ingests a batch of events in a single request. Accepts an array ofEventPayload objects. The server assigns a UUID and the same UTC timestamp to every event in the batch before persisting them in a single transaction.
Request body
An array ofEventPayload objects. Each object has the same fields as the single-event endpoint above.
Response
Returns202 Accepted with an empty body on success.
| Status | Meaning |
|---|---|
202 Accepted | All events saved (or array was empty) |
400 Bad Request | Request body is not valid JSON |
413 Request Entity Too Large | Batch exceeds 50 events |
500 Internal Server Error | Database write failed |
Examples
The Iris SDK has built-in batching support. Pass a
batching config to new Iris({...}) to queue events and flush them automatically via this endpoint instead of /api/event.