> For the complete documentation index, see [llms.txt](https://docs.zero.inc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zero.inc/developers/api/analytics-events.md).

# Sending Analytics Events

Usage from your own product (API calls, documents created, seats used) is the same early signal as web analytics, and you can send it to Zero yourself instead of syncing it from [PostHog](https://docs.zero.inc/settings/integrations/posthog.md). Post daily event counts per person or company. Zero links them to matching contacts and companies, and they show up wherever synced analytics events do.

## Send events

```
POST /api/analyticsEvents/batch
```

The body is a JSON array of 1 to 500 events.

### Event fields

Every event needs a `workspaceId`, a `type`, a `date` or `time`, and at least one identifier: `email`, `domain`, `contactId` or `companyId`.

| Field         | Type                | Required         | Description                                                                                                    |
| ------------- | ------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------- |
| `workspaceId` | string              | Yes              | Your workspace ID. The API token must belong to this workspace.                                                |
| `type`        | string              | Yes              | Event name, such as `api_call`. It is the event type you pick in Zero's columns, filters and reports.          |
| `date`        | string (YYYY-MM-DD) | `date` or `time` | Day the events happened. Zero counts events per day.                                                           |
| `time`        | string (ISO 8601)   | `date` or `time` | When the event happened. Without `date`, Zero files it under the UTC day of `time`.                            |
| `email`       | string              | One identifier   | Email of the person who triggered the event. Used to find the contact.                                         |
| `domain`      | string              | One identifier   | Company domain, such as `acme.com`. Taken from `email` when left out. Used to find the company.                |
| `contactId`   | string              | One identifier   | Zero contact ID, to link the event to a contact directly.                                                      |
| `companyId`   | string              | One identifier   | Zero company ID, to link the event to a company directly.                                                      |
| `count`       | integer             | No               | How many times the event happened that day. Defaults to `1`.                                                   |
| `properties`  | object              | No               | Any JSON object, stored as sent, such as `{"plan": "pro", "tokens": 1200}`. Zero does not read or validate it. |

### Query parameters

| Parameter | Type    | Description                                                                                                                                                                                                                |
| --------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `upsert`  | boolean | `true` or `1` updates the stored row for the same event, person or company, and day instead of adding a new one. Any other value, or leaving it out, adds a new row. See [Updating a day's count](#updating-a-days-count). |

### Example

```bash
curl -X POST "https://api.zero.inc/api/analyticsEvents/batch" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '[
    {
      "workspaceId": "WORKSPACE_UUID",
      "type": "api_call",
      "date": "2026-10-28",
      "email": "jane@acme.com",
      "count": 42,
      "properties": { "plan": "pro" }
    },
    {
      "workspaceId": "WORKSPACE_UUID",
      "type": "report_exported",
      "time": "2026-10-28T14:03:00Z",
      "domain": "globex.com"
    }
  ]'
```

### Response

```json
{
  "data": [
    {
      "id": "EVENT_UUID",
      "workspaceId": "WORKSPACE_UUID",
      "type": "api_call",
      "date": "2026-10-28",
      "email": "jane@acme.com",
      "domain": "acme.com",
      "contactId": "CONTACT_UUID",
      "companyId": "COMPANY_UUID",
      "count": 42,
      "properties": { "plan": "pro" }
    },
    {
      "id": "EVENT_UUID",
      "workspaceId": "WORKSPACE_UUID",
      "type": "report_exported",
      "date": "2026-10-28",
      "email": null,
      "domain": "globex.com",
      "contactId": null,
      "companyId": "COMPANY_UUID",
      "count": 1,
      "properties": null
    }
  ],
  "errors": []
}
```

`data` has one entry per event, in the order you sent them, and `errors` lists the events Zero could not store. `errors` is empty when every event was stored.

An event that can't be stored, for example because its `workspaceId` is one the token cannot reach, does not stop the others. It is `null` in its place in `data` and has an entry in `errors`, and the request still returns `200`, so check `errors` rather than the status code:

```json
{
  "data": [{ "id": "EVENT_UUID", "type": "api_call", "date": "2026-10-28", "count": 42 }, null],
  "errors": [
    {
      "index": 1,
      "statusCode": 403,
      "error": "Writing to workspace is not allowed",
      "code": "forbidden",
      "path": "workspaceId"
    }
  ]
}
```

| Field        | Description                                                                                                                                                                                                        |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `index`      | Position of the event in the request body, counting from 0.                                                                                                                                                        |
| `statusCode` | The HTTP status the event would have had on its own. A `4xx` means the event itself is at fault, so sending it again unchanged fails again. A `5xx` is a failure on Zero's side, and you can send the event again. |
| `error`      | What went wrong.                                                                                                                                                                                                   |
| `code`       | A machine readable code, such as `forbidden`. Left out for unexpected failures.                                                                                                                                    |
| `path`       | The event field at fault, such as `workspaceId`, when there is one.                                                                                                                                                |
| `hint`       | How to fix the event, when Zero can tell.                                                                                                                                                                          |

## How counts are stored

Zero works in daily totals: a row holds the `count` of one event type for one person or company on one day, and every view adds `count` up across rows.

Without `upsert`, every event becomes a new row, even when that day already has one. Totals stay right because Zero sums `count`, so the simplest integration posts each batch's counts as new events and lets Zero add them up.

### Updating a day's count

With `?upsert=true`, an event updates the stored row that has the same `workspaceId`, `type` and `date`, and the same value for each of `email`, `domain`, `contactId` and `companyId` that the event carries:

* Without `count`, the stored count goes up by 1.
* With `count`, the stored count is **replaced**. Send the day's running total, not the number since the last request.
* Other fields you send, such as `properties`, replace the stored values.
* When no row matches, the event is stored as a new row. Two events in the same request that match no stored row become two rows, so combine them before sending.

The match only compares the identifiers the event carries. Send the same identifiers for a person every time: an event with only `"domain": "acme.com"` can update a row that also has `"email": "jane@acme.com"`.

## How events link to contacts and companies

* An event with an `email` and no `contactId` is linked to the contact with that address, primary or additional, ignoring letter case, and to that contact's company unless you sent `companyId`.
* When the event has no email, or its email matches no contact, Zero links it to the company with its `domain`, which it takes from `email` when you leave `domain` out.
* `contactId` and `companyId` link the event directly. With `contactId` alone, the company is still found by domain.
* Zero links an event once, when it receives it. Contacts and companies you add afterwards are not linked to events sent before, and there is no resync as there is for PostHog. Create the records first, or send their IDs.
* Zero never creates contacts or companies from events. An event that matches neither is still stored and counted in reports, but appears on no record.

## Where the events appear

Events you send appear in the same places as events synced from PostHog. See [Where the data appears in Zero](https://docs.zero.inc/settings/integrations/posthog.md#where-the-data-appears-in-zero) for screenshots.

* The **Analytics events** column on company and contact lists. Your event types are listed under **Event types** in the column settings.
* The **Last analytics event → Type** and **Last analytics event → Date** columns, for sorting and filtering by recent activity.
* **Reports**, with **Analytics events** as the entity.

The **Analytics sessions** columns and session entries in the activity feed come only from PostHog. Events sent through this endpoint do not create sessions.

## Reading events back

Stored events are read like any other resource:

```bash
curl -G "https://api.zero.inc/api/analyticsEvents" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  --data-urlencode 'where={"workspaceId":"WORKSPACE_UUID","type":"api_call","date":{"$gte":"2026-10-01"}}' \
  --data-urlencode 'fields=id,type,date,email,contactId,companyId,count'
```

To list the event types a workspace has, from this endpoint and from PostHog alike:

```bash
curl "https://api.zero.inc/api/analyticsEvents/eventTypes?workspaceId=WORKSPACE_UUID" \
  -H "Authorization: Bearer YOUR_API_TOKEN"
```

## Errors

Zero checks every event before storing any of them. The whole request is rejected with `400 Bad Request`, nothing is stored, and the `error` field names the rule that failed when:

* the body is not an array, is empty, or holds more than 500 events
* an event is not a JSON object, is missing `workspaceId` or `type`, or has neither `date` nor `time`
* an event has a value of the wrong kind: a `workspaceId`, `contactId` or `companyId` that is not a UUID, a `type`, `email` or `domain` that is not a string, a `date` that is not `YYYY-MM-DD`, or a `time` that is not a valid timestamp. The `error` field names the field and the event's position, such as `Invalid contactId on analyticsEvent 3`
* an event has none of `email`, `domain`, `contactId` and `companyId`

```json
{ "error": "Too many batch events (maximum is 500)" }
```

Fix the request before sending it again. Events that pass these checks but can't be stored, such as one whose `workspaceId` the token cannot reach, don't fail the request. They are reported in `errors` in the [response](#response).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zero.inc/developers/api/analytics-events.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
