# Registrar evento de analítica del portal

POST `https://api.bydomu.com/v1/events`

Registra una vista, búsqueda o clic del portal para su analítica. Se procesa en segundo plano: la respuesta es inmediata y no confirma que el evento se haya guardado. Responde `200`, no `201`.

Permiso que pide

`events:write`

Encabezado obligatorio

`X-API-Key` · clave publicable o secreta

Nivel de acceso

Nivel 1 · sin solicitud

## Encabezados

1 · todos opcionales

`Idempotency-Key` string · opcional

Clave única de la operación (8-128 caracteres de `[a-zA-Z0-9._:-]`). Un reintento con la misma clave y el mismo cuerpo devuelve la respuesta original sin repetir la operación. Vive 24 horas. 8–128 chars

## Cuerpo (JSON)

5 · 1 obligatorios

`type` string · **obligatorio**

PAGE_VIEW · PROPERTY_VIEW · SEARCH · LEAD_FORM · WHATSAPP_CLICK · CALL_CLICK · SCHEDULE_CLICK · SHARE_CLICK · FINDER_SUBMIT

`propertyId` string · opcional

`searchQuery` string · opcional

≤ 200 chars

`referrer` string · opcional

≤ 500 chars

`metadata` object · opcional

## Respuesta 200

`SuccessFlag` · 1 campos

**`data` La operación se aceptó.**

`success` boolean true

## Errores posibles

con la forma `{ "error": { "code", "message" } }`

- **400** Datos inválidos: el cuerpo o la query no cumplen el esquema, o `Idempotency-Key` está mal formada.
- **401** UNAUTHORIZED
- **402** PAYMENT_REQUIRED
- **403** FORBIDDEN
- **409** DUPLICATE
- **429** RATE_LIMITED
- **500** INTERNAL_ERROR

cURL:

```bash
curl -X POST "https://api.bydomu.com/v1/events" \
  -H "X-API-Key: $BYDOMU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "type": "PROPERTY_VIEW",
  "propertyId": "clx1prop001",
  "referrer": "https://google.com"
}'
```

JavaScript:

```js
import { ByDomu } from "@bydomu/sdk";

const bydomu = new ByDomu({
  apiKey: process.env.BYDOMU_API_KEY,
});

const { data } = await bydomu.events.track({
  "type": "PROPERTY_VIEW",
  "propertyId": "clx1prop001",
  "referrer": "https://google.com"
});
```

Python:

```python
import os, requests

r = requests.post(
    "https://api.bydomu.com/v1/events",
    headers={"X-API-Key": os.environ["BYDOMU_API_KEY"]},
    json={
        "type": "PROPERTY_VIEW",
        "propertyId": "clx1prop001",
        "referrer": "https://google.com"
    }
)
data = r.json()
```

**Respuesta · 200 · ejemplo**

```json
{
  "data": {
    "success": true
  }
}
```
