# Track customer events

Record product actions like order.placed or checkout.started from your server API or the browser messenger.

Tracked events power [audiences](/customers/audiences/), trigger [series](/outbound/series/), and emit the `contact_event.tracked` [webhook](/developers/webhooks/events/).

Event names use 1 to 64 lowercase letters, digits, and `_ . : -`. Optional metadata supports up to 20 keys and 2 KB per event.

## Track events from your server

Send events to [`POST /api/v1/contact-events`](/api-reference/contacts-and-companies/create-contact-event/) using an API token with `contacts:write`:

```bash
curl -X POST https://trydimmi.com/api/v1/contact-events \
  -H "Authorization: Bearer <api_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "order.placed",
    "external_id": "42",
    "metadata": { "order_id": "A-1001", "total": 129.5 },
    "idempotency_key": "order-A-1001"
  }'
```

- **Identify the customer:** pass one of `contact_id`, `email`, or `external_id` (the `sub` claim from their [identity token](/developers/messenger/identity-verification/)).
- **Avoid duplicates:** dimmi deduplicates matching `idempotency_key` values for 48 hours.
- **Batch events:** wrap up to 100 events in an `events` array to send them in one request.

## Track events from the browser

```ts title="src/checkout.ts"

getDimmi().trackEvent("checkout.started", { plan: "team", seats: 5 });
```

Using the script tag instead? Call `Dimmi("track", "checkout.started", { plan: "team", seats: 5 })`.

Because anyone can call browser JavaScript, dimmi only accepts browser event names you enable under **Settings → Attributes → Events** (unless you turn on **Accept any event from the messenger**). Always send security-sensitive or billing events from your server.

The messenger queues browser events until the visitor has an active session (signed in, or previously started a chat).

---

Index of all dimmi docs: https://trydimmi.com/llms.txt (full text: https://trydimmi.com/llms-full.txt)
