POST /track/events/batch
Records multiple events in a single request. Used by the frontend tracker script to flush queued events every 5 seconds.
Request Body
json
{
"session_id": "550e8400-e29b-41d4-a716-446655440000",
"visitor_id": "a1b2c3d4e5f6...",
"events": [
{ "event_type": "scroll", "scroll_percent": 25, "page": "https://example.com/home", "timestamp": 1740000000000 },
{ "event_type": "click", "x": 400, "y": 200, "page": "https://example.com/home", "timestamp": 1740000001000 },
{ "event_type": "page_view", "page": "https://example.com/about", "timestamp": 1740000002000 }
]
}| Field | Required | Description |
|---|---|---|
session_id | Yes | Session ID |
events | Yes | Non-empty array of events (max 100) |
visitor_id | No | Visitor ID |
Each event in the array supports the same fields as /track/event.
Response (200)
json
{
"accepted": 3,
"timestamp": 1740000000000
}Limits
- Maximum 100 events per batch request
- Events exceeding the limit receive a
400error
Background Processing
- Batch-insert all events to D1 using
DB.batch()(single round trip) - Update session
last_seenandexit_pagewith the last event - Append event batch to R2 as a single archive file
Errors
| Status | Condition |
|---|---|
| 400 | Invalid JSON body |
| 400 | Missing session_id or empty events[] |
| 400 | Batch size exceeds 100 |