POST /track/event
Records a single tracking event (click, scroll, page view, etc.) for an active session.
Request Body
json
{
"session_id": "550e8400-e29b-41d4-a716-446655440000",
"visitor_id": "a1b2c3d4e5f6...",
"event_type": "click",
"page": "https://example.com/home",
"x": 150,
"y": 300,
"scroll_percent": 0,
"element": "BUTTON#cta.primary",
"timestamp": 1740000000000
}| Field | Required | Description |
|---|---|---|
session_id | Yes | Session ID from /track/session/start |
event_type | Yes | One of: page_view, scroll, click, mousemove, navigation, visibility_change |
visitor_id | No | Visitor ID |
page | No | Current page URL |
x, y | No | Mouse/click coordinates (default 0) |
scroll_percent | No | Scroll depth 0-100 (default 0) |
element | No | CSS selector of interacted element |
timestamp | No | Client timestamp (defaults to Date.now()) |
Response (200)
json
{
"event_id": "550e8400-e29b-41d4-a716-446655440001",
"timestamp": 1740000000000
}Background Processing
- Store event to D1
eventstable - Update session
last_seenandexit_page - Append event to R2 session archive
Errors
| Status | Condition |
|---|---|
| 400 | Invalid JSON body |
| 400 | Missing session_id or event_type |