# Metrics Ingestion

The Metrics Ingestion API allows supported integrations to submit engagement and usage events generated outside Firstup so that this activity can be included alongside Firstup-generated activity in reporting.

The API accepts batches of events. Each event identifies what happened, what the action happened to, where it happened, and who the event belongs to.

## How Metrics Ingestion works

A typical integration follows this flow:

1. Obtain an OAuth 2.0 access token with the required `metrics.write` scope.
2. Create one or more metric events.
3. Submit the events to the Metrics Ingestion API.
4. Firstup validates the complete batch.
5. Valid events are routed to the internal system responsible for the relevant metric.
6. The accepted events become available for reporting after downstream processing.


The API determines where an event is routed from the event's `action`. The `action`, `object`, and `platform` determine how the event is recorded at the destination. The integration does not specify a reporting destination directly.

## Authentication

The Metrics Ingestion API uses OAuth 2.0.

Obtain an access token with the `metrics.write` scope and include it in the request's `Authorization` header:

```http
Authorization: Bearer <access_token>
```

The `metrics.write` scope allows an application to submit metric events. Both client credentials tokens and user access tokens obtained through the authorization code flow can be used when they include this scope.

See [Authorization Methods](/authorization/authentication-methods) for instructions on obtaining an access token.

## Events

Each event describes a single occurrence of an action.

| Field | Purpose |
|  --- | --- |
| `action` | What the user did. |
| `object` | What the action happened to. |
| `platform` | Where the action happened. |
| `occurred_at` | When the action occurred. |
| `user_id` or `anonymous_id` | Who the event belongs to. |
| `event_id` | An optional identifier supplied by your integration. |
| `properties` | Additional information associated with the event. |
| `context` | Device, session, and application information. |


### Actions

The API currently supports three actions:

| Action | Description |
|  --- | --- |
| `click` | The user activated something, such as a card, link, or button. |
| `open` | The user opened something, such as a deep link or post. |
| `view` | The user saw something, such as a card, profile, or carousel. |


The supported `object` values depend on the action.

See the [Metrics Ingestion Event Catalogue](/dataexports/metrics_ingestion_event_catalogue) for the complete list of supported action/object combinations.

### Platforms

Each event must include `platform` with one of these values:

- `web`
- `ios`
- `android`


Use the value that identifies where the interaction occurred. Not every action/object combination supports all three platforms. For example:

- `click` with `QuickLinks` supports `web` only.
- `open` with `DeeplinkEmail` or `DeeplinkPush` supports `ios` and `android` only.
- `open` with `post` supports `android` only.
- `view` with `HighlightsCard` supports `android` only.


The API rejects unsupported action/object/platform combinations with `400 Bad Request`. If one event uses an unsupported combination, the entire batch is rejected and no events are forwarded.

The API action `open` is not a general-purpose value for every interaction described as an open in reporting. It is not supported on `web`. Select the registered action/object combination that matches the interaction, rather than choosing an action from a report metric's name alone.

See the [Metrics Ingestion Event Catalogue](/dataexports/metrics_ingestion_event_catalogue) for the supported events. Platform support must also be checked for the selected action/object combination.

### Objects

The `object` identifies what an action occurred on. For example:

```json
{
  "action": "click",
  "object": "ContentCard",
  "platform": "web"
}
```

Objects can also represent more specific interactions. For example:

```json
{
  "action": "click",
  "object": "ContentCard:Comment:Reaction:Like",
  "platform": "web"
}
```

These examples show the action, object, and platform only. A submitted event must also include the attribution fields described below and must be sent inside the `events` array.

An object is only valid when it is registered for the specified action and supports the specified platform. An unsupported combination is rejected with `400 Bad Request`.

The complete list of supported action/object combinations is maintained in the [Metrics Ingestion Event Catalogue](/dataexports/metrics_ingestion_event_catalogue).

## When to generate events

The integration is responsible for detecting interactions and generating events. The API validates submitted events; it does not determine whether a card was visible or whether an interaction has already generated an event in the application.

To align content-card impressions with Firstup's Web Experience:

- Generate an impression when the content card is fully visible: 100% of the card must be in view.
- No minimum dwell time is required once the card is fully visible.
- Suppress repeated impressions for the same `content_id` while the page's JavaScript module state persists.
- Allow another impression after a full page reload, hard refresh, or opening the content in a new tab, which resets that state.


Firstup's Web Experience can generate open and click events repeatedly when users repeat those interactions.

These rules describe Firstup's Web Experience and provide guidance for matching its measurement behaviour. They are not additional API validation requirements or a definition of mobile behaviour. Any suppression of repeated impressions must happen in the integration; the Metrics Ingestion API does not de-duplicate submissions.

For example, use `view` with `ContentCard` for a content-card impression. The catalogue also includes `view` with `ContentCard:Read` for a content card opened to read. Choose events that describe the actual interaction.

## Batching

Events are submitted as a single batch using the `events` array.

A batch must contain at least one event and can contain up to 500 events.

A batch can contain different actions. For example, a single request can contain both `click` and `view` events.

```json
{
  "events": [
    {
      "action": "click",
      "object": "ContentCard",
      "platform": "web",
      "user_id": "104883",
      "properties": {
        "content_id": 88213
      }
    },
    {
      "action": "view",
      "object": "NotificationCard",
      "platform": "ios",
      "user_id": "104883",
      "properties": {
        "notification_id": 9124
      }
    }
  ]
}
```

## Validation

Metrics Ingestion validates the complete batch before forwarding events.

Batches are all-or-nothing. If any event fails validation:

- the request returns `400 Bad Request`
- no events in the batch are forwarded


Validation can fail when an event contains an invalid or unsupported action/object combination, or when a required event value is missing or invalid.

## Attribution

Each event must identify the user it belongs to using either `user_id` or `anonymous_id`.

- Use `user_id` when the event can be associated with a Firstup user.
- Use `anonymous_id` when the event cannot be associated with a known user.


An event must contain at least one of these identifiers.

## Event properties and context

Use `properties` to provide additional information about an event.

The reporting system recognises specific properties, including:

- `content_id`
- `content_channel_id`
- `content_channel_name`
- `feed_item_id`
- `notification_id`
- `tok`


For events associated with Firstup content, include the relevant `properties.content_id` so that the activity can be attributed to that content. The API can accept content events without this value, but accepting an event does not establish its association with a particular campaign or content item. When supplied for content-card events, `content_id` must be a string or a number.

Other properties can be supplied and are forwarded to the destination unchanged.

Use `context` to provide information about the device, session, and application in which the event occurred.

The reporting system recognises values including:

- `traits.program_id`
- `traits.advocate_id`
- `app.version`


`traits.program_id` is derived from the actor token and overrides a value supplied in the request.

## Event timestamps

Use `occurred_at` to provide the ISO 8601 timestamp for when the event occurred.

If `occurred_at` is omitted, the API uses the time the request was received.

## Event identifiers and retries

You can provide your own `event_id` to help identify an event.

`event_id` is not an idempotency key. Metrics Ingestion does not de-duplicate events using this value. This means that submitting the same event more than once can result in the event being recorded more than once.

When retrying a failed request, use the retry information returned by the API to determine whether resending the request is safe.

## Successful ingestion

A successful request returns:

```
202 Accepted
```

The response indicates that:

- all events in the batch passed validation
- the destination accepted the batch
- the events have been accepted for downstream processing


A successful response does not mean that the events are immediately available in reporting.

The response includes a `request_id` that can be used when investigating a request or reporting a problem.

## Errors and retry behavior

Metrics Ingestion can return validation, authentication, request, and downstream errors.

The API uses a `retry` value to indicate what happens if the same request is submitted again:

| Value | Meaning |
|  --- | --- |
| `no` | Retrying the request will fail in the same way and nothing was forwarded. |
| `yes` | Nothing reached the destination and retrying the request is considered safe. |
| `unknown` | The destination may already have accepted the batch, so retrying may result in duplicate events. |


For batches spanning multiple destinations, the response can also identify actions that were already delivered.

Do not resend events that have already been delivered, because downstream systems do not de-duplicate events.

## API Reference

Use the [Metrics Ingestion API Reference](/endpoints/openapi/metrics) for the endpoint definition, request and response schemas, authentication requirements, and error responses.

For the supported action/object combinations, see the [Metrics Ingestion Event Catalogue](/dataexports/metrics_ingestion_event_catalogue).