# Collect an analytics event

**Publié le** : 2026-05-12
**Catégorie** : Analytics & Tracking

## `POST /analytics/collect`

**Collect an analytics event**

Ingest one analytics event. The endpoint is fire-and-forget:
validation errors, excluded IPs, excluded paths, disabled tracking
on the site, and localhost origins all return 202 with a
descriptive `message`. This is by design to avoid client-side
error noise. The body field set follows the
`collectAnalyticsValidator` schema (event name, page path, optional
properties).

### Request Body

Content-Type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `session_id` | string | Yes | Required |
| `visitor_id` | string | Yes | Required. 8-64 characters |
| `cookie_visitor_id` | string \| null | No |  |
| `visitor_id_source` | "cookie" \| "fingerprint" \| "hybrid" | No | One of: cookie, fingerprint, hybrid |
| `event_type` | "pageview" \| "scroll" \| "time_on_page" \| "cwv" \| "exit" \| "heartbeat" \| "click" \| "outbound_link" \| "file_download" \| "email_click" \| "phone_click" \| "rage_click" \| "dead_click" \| "copy" \| "form_start" \| "form_submit" \| "form_abandon" \| "form_field" \| "form_error" \| "heatmap_click" | Yes | Required. One of: pageview, scroll, time_on_page, cwv, exit, heartbeat, click, outbound_link, file_download, email_click, phone_click, rage_click, dead_click, copy, form_start, form_submit, form_abandon, form_field, form_error, heatmap_click |
| `page_url` | string | No | Max 2048 characters |
| `page_path` | string | Yes | Required. Max 1024 characters |
| `event_time` | string | Yes | Required |
| `page_title` | string | No | Max 500 characters |
| `page_referrer` | string \| null | No |  |
| `scroll_depth` | number \| null | No |  |
| `time_on_page` | number \| null | No |  |
| `engaged_time` | number \| null | No |  |
| `lcp` | number \| null | No |  |
| `fid` | number \| null | No |  |
| `cls` | number \| null | No |  |
| `ttfb` | number \| null | No |  |
| `inp` | number \| null | No |  |
| `utm_source` | string \| null | No |  |
| `utm_medium` | string \| null | No |  |
| `utm_campaign` | string \| null | No |  |
| `utm_term` | string \| null | No |  |
| `utm_content` | string \| null | No |  |
| `traffic_source` | "direct" \| "organic" \| "social" \| "paid" \| "referral" \| "email" \| "internal" \| "ai" \| null | No |  |
| `device_type` | "desktop" \| "laptop" \| "mobile" \| "tablet" \| null | No |  |
| `browser` | string \| null | No |  |
| `browser_version` | string \| null | No |  |
| `os` | string \| null | No |  |
| `os_version` | string \| null | No |  |
| `screen_width` | number \| null | No |  |
| `screen_height` | number \| null | No |  |
| `language` | string \| null | No |  |
| `timezone` | string \| null | No |  |
| `referrer_domain` | string \| null | No |  |
| `is_entry` | boolean | No | Boolean |
| `is_exit` | boolean | No | Boolean |
| `visible` | boolean | No | Boolean |
| `max_scroll_depth` | number \| null | No |  |
| `click_x` | number \| null | No |  |
| `click_y` | number \| null | No |  |
| `click_element` | string \| null | No |  |
| `click_element_tag` | string \| null | No |  |
| `click_element_id` | string \| null | No |  |
| `click_element_class` | string \| null | No |  |
| `click_element_text` | string \| null | No |  |
| `click_target_url` | string \| null | No |  |
| `click_count` | number \| null | No |  |
| `viewport_width` | number \| null | No |  |
| `viewport_height` | number \| null | No |  |
| `file_name` | string \| null | No |  |
| `file_extension` | string \| null | No |  |
| `file_url` | string \| null | No |  |
| `copied_text` | string \| null | No |  |
| `scroll_behavior` | "reading" \| "skimming" \| "jumping" \| null | No |  |
| `form_id` | string \| null | No |  |
| `form_name` | string \| null | No |  |
| `field_name` | string \| null | No |  |
| `field_type` | string \| null | No |  |
| `field_time` | number \| null | No |  |
| `error_message` | string \| null | No |  |
| `form_completion_rate` | number \| null | No |  |


### Responses

| Status | Description |
| --- | --- |
| `201` | Successful response |
| `422` | Validation error |


> **Notes:** Returns HTTP 202 Accepted in all non-error cases (validation
> failure, excluded IP, excluded path, disabled tracking, localhost
> origin). The `message` describes the disposition; clients should
> not treat 202 as a hard success. Rate-limit bucket: analytics
> (~1200 rpm per IP).

### Examples

```curl
curl -X POST "https://api.lynkow.com/public/{siteId}/analytics/collect" \
  -H "Content-Type: application/json" \
  -d '{ "event": "page_view", "path": "/pricing" }'
```

```javascript
navigator.sendBeacon(
  `https://api.lynkow.com/public/${siteId}/analytics/collect`,
  JSON.stringify({ event: 'page_view', path: '/pricing' })
)
```

### Response Example

```json
"{\n  \"message\": \"Event received\"\n}\n"
```

---