# Reporting and exports

> Get decisions and outcomes out of Herald with the CSV export, Slack alerts, signed outbound webhooks, Google Sheets and hashed ad audiences, with a daily sync to Meta, Google Ads and LinkedIn.

:::note Built and tested against each vendor's documented API; tell us if anything differs in your account.:::

Slack, outbound webhooks and Google Sheets are integrations you set up in **Settings → Integrations**, under Send results out. They run on the hourly sync. The CSV downloads need no setup. The ad audience CSV needs none either; the daily ad audience sync is an integration too.

## What you'll need

- An admin of the account. Integrations are set up in **Settings → Integrations**.
- **Decisions CSV by API:** an API key with the `exports.read` scope.
- **Slack:** an incoming webhook URL for the channel.
- **Outbound webhooks:** a public HTTPS endpoint you control.
- **Google Sheets:** a service account JSON key, and the sheet shared with that account as an editor.
- **Ad audiences:** an ad account on Meta, Google Ads or LinkedIn, and credentials for it.

## Decisions CSV

**API.** `GET /api/v1/exports/decisions.csv?from=YYYY-MM-DD&to=YYYY-MM-DD` with `Authorization: Bearer hk_…`, an API key with the `exports.read` scope. Both days are included (UTC), and the range is at most 31 days (`400` otherwise). A key without the scope answers `403`. Each request counts toward `exports.requests`, 60 per hour by default.

**Console.** **Download CSV** on the Overview header (admins) downloads the page's period (7, 30 or 90 days).

The file has one row per decision sent in the range, in send order, with outcomes as of the download: `decision_id, user_id, agent_id, agent_name, variant_id, variant_name, channel, sent_at, converted_at, conversion_event, reward, holdout`. It is UTF-8 with a header row, RFC 4180 quoting and CRLF line ends.

### Common errors

| Message | Cause | Fix |
|---|---|---|
| `from must be a date (YYYY-MM-DD)`, `to must not be before from` or `The range can be at most 31 days` | `400`: a bad range | Fix `from` and `to` |
| `This API key lacks the exports.read scope` | `403`: the key lacks the scope | Create a key with `exports.read` |
| `Rate limit exceeded for exports.requests: 60 per hour` | `429`: over the hourly limit | Wait for `Retry-After` |

## Slack alerts

Paste a Slack **incoming webhook URL**. It must start with `https://hooks.slack.com/`. Each alert is on by default.

| Alert | Sent when |
|---|---|
| `liftNegative` | An on agent's lift against its holdout is negative and significant |
| `winnerFound` | A sending agent's leading variant has at least 70% of its last 7 days' sends (20 or more) |
| `sendFailures` | Messages of the app failed to send in the last hour |

Each alert goes out at most once per agent (per app for send failures) every 24 hours. The message is one line of plain text with a link to the agent in the console. **Send test** posts "Connected" to the channel.

### Common errors

| Message | Cause | Fix |
|---|---|---|
| `Slack answered HTTP <status>` | Shown as the last error: Slack refused the post, often a removed webhook | Create a new incoming webhook and update the integration |
| `Slack timed out after 10 s` or `Slack request failed` | Slack couldn't be reached | None: the next run retries |

## Outbound webhooks

Give an https URL and pick the events: `decision.created` (a decision was sent) and `outcome.recorded` (a decision converted). The console shows a signing secret once. Each hourly sync posts every new event since the last delivery as a JSON array, up to 500 per request.

```json
[
  {
    "type": "decision.created",
    "id": "decision.created:cmh1x2y3z0001",
    "created_at": "2026-11-20T09:00:00.000Z",
    "data": {
      "decision_id": "cmh1x2y3z0001", "user_id": "user_42", "agent_id": "cmh0agent", "agent_name": "Welcome",
      "variant_id": "cmh0var", "variant_name": "Short", "channel": "push", "sent_at": "2026-11-20T09:00:00.000Z",
      "converted_at": null, "conversion_event": null, "reward": null, "holdout": false
    }
  }
]
```

`outcome.recorded` carries the same `data` with `converted_at`, `conversion_event` and `reward` set, and its `created_at` is the conversion time. `id` is unique per event: use it to drop repeats.

Headers: `X-Herald-Signature: sha256=<hex HMAC-SHA256(secret, raw body)>` and `X-Herald-Timestamp` (Unix seconds when sent).

A batch moves past only when your endpoint answers 2xx within 10 seconds. Otherwise it is sent again next hour and the failure shows as the last error. Redirects are not followed. A URL on a private, loopback, link-local or reserved address is refused. A new webhook starts from the time it was created. Delivery is hourly. **Send test** posts one signed `{ "type": "test" }` event.

Verify the signature over the raw body before you parse it.

**Node**

```js
import { createHmac, timingSafeEqual } from "node:crypto";
function verified(rawBody, header, secret) {
  const expected = "sha256=" + createHmac("sha256", secret).update(rawBody).digest("hex");
  return header?.length === expected.length && timingSafeEqual(Buffer.from(header), Buffer.from(expected));
}
```

**Python**

```python
import hashlib, hmac
def verified(raw_body: bytes, header: str, secret: str) -> bool:
    expected = "sha256=" + hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(header or "", expected)
```

In Zapier use **Webhooks by Zapier → Catch Hook**, in Make a **Custom webhook**, and in n8n a **Webhook** node. Paste its URL into the console.

### Common errors

| Message | Cause | Fix |
|---|---|---|
| `The endpoint answered HTTP <status>` | Your endpoint answered with an error | Check your endpoint's logs |
| `The endpoint timed out after 10 s` or `The endpoint request failed` | Your endpoint didn't answer in time | Answer within 10 seconds and do the work later |
| `The endpoint URL must be https on a public address` | The URL isn't public HTTPS | Use a public `https://` URL |
| `url must be an https URL` or `Choose at least one event` | Saving the integration: a bad URL or no events | Fix the field |

## Google Sheets

1. Create a Google Cloud service account, enable the Google Sheets API on its project and create a JSON key. Paste the key into the console.
2. Share the spreadsheet with the service account's `client_email` as an Editor.
3. Enter the `spreadsheetId` (from the URL, `/d/<id>/edit`) and the `sheetName` (the tab).

The first sync at or after 03:00 UTC each day appends one row per active agent for the previous UTC day. The first append adds a header row.

| Date | Agent | Sends | Conversions | Conversion rate | Lift vs holdout | Top variant |
|---|---|---|---|---|---|---|
| 2026-11-19 | Welcome | 1200 | 84 | 0.07 | 0.123 | Short |

Rates are fractions, so format the column as a percentage. Lift is the agent's holdout lift to date when it is ready, otherwise blank. The top variant has the most conversions that day. **Test** reads the sheet's metadata and checks the tab exists. It writes nothing.

To chart the sheet, see [BigQuery, Firebase and Snowflake](/docs/integrations/warehouses).

### Common errors

| Message | Cause | Fix |
|---|---|---|
| `Google Sheets: <message>` or `Google Sheets answered HTTP <status>` | Google refused the write, often because the sheet isn't shared with the service account | Share the sheet with the service account as an editor |
| `"<title>" has no sheet named "<sheet>"` | **Test**: the tab doesn't exist | Fix `sheetName` |
| `The service-account key is not JSON` | The secret isn't a JSON key | Paste the whole JSON key file |
| `spreadsheetId is the id in the sheet's URL (/d/<id>/)` | Saving the integration: a bad id | Copy the id from the sheet's URL |

## Ad audiences

Each segment row has an **Export for ads** menu (admins). It downloads `GET /api/segments/{id}/audience.csv?format=meta`, `google` or `linkedin`, with one line per segment member who has an active email or phone. Any suppression of the address (unsubscribe, bounce, complaint, STOP, manual) leaves it out. Values are normalized and then SHA-256 hashed (lowercase hex).

| Platform | Columns | Email | Phone |
|---|---|---|---|
| Meta Custom Audiences | `email,phone` | Trimmed, lower case | Digits with country code, no `+` |
| Google Customer Match | `Email,Phone` | Trimmed, lower case; for gmail.com and googlemail.com the dots and `+suffix` before `@` are removed | E.164 with `+` |
| LinkedIn Matched Audiences | `email` | Trimmed, lower case | Not used |

Upload the file in each platform's audience manager as a customer list with pre-hashed data. The CSV also works for a one-off upload; the daily sync below replaces it for Meta, Google Ads and LinkedIn.

### Daily sync (Beta)

Set up one integration per platform account (**Meta**, **Google Ads** or **LinkedIn**) in **Settings → Integrations**, under Send results out. Config: the account plus 1 to 10 pairs of a segment and an audience (the segment must belong to the account). Each day, on the first sync at or after 04:00 UTC, each pair's audience is made equal to the segment's members, built exactly as the CSV builds them (same member query, normalization, hashing and suppressions). A pair with no audience gets a new one named after the segment on its first sync. Each pair shows its last sync time, how many were sent and its last error; a failing pair doesn't stop the others. Herald doesn't hold back a segment below a platform's minimum size: it sends it and records the answer. **Sync now** runs every pair at once, whatever the hour. Tokens are stored encrypted. **Test** signs in and reads the account, writing nothing.

- **Meta.** Secret: a system user access token with `ads_management`, for a system user that has the ad account. Accept the Custom Audience terms for the ad account. Config: `adAccountId` (`act_<digits>`; bare digits get the prefix). Meta can't replace an audience with nobody, so an empty segment leaves the audience as it was. Matching can take up to 24 hours, and an audience needs roughly 100 matched people to deliver.
- **Google Ads.** Uses Google's Data Manager API. Secret: JSON `{ clientId, clientSecret, refreshToken, loginCustomerId? }` for an OAuth client from a Google Cloud project with the Data Manager API enabled, and a refresh token for a Google account with access to the Google Ads account, granted the `https://www.googleapis.com/auth/datamanager` scope. `loginCustomerId` is the manager account when the user signs in through one. No developer token is needed. Accept the Customer Match terms in Google Ads. Config: `customerId` (dashes optional). Herald sends no consent signals, so Google treats them as unspecified and members in the EEA may not be used. Processing can take up to 48 hours, and a list needs at least 100 active matched members to serve.
- **LinkedIn.** Secret: JSON `{ clientId, clientSecret, refreshToken }` for an app with the Advertising API and the Audiences program (`rw_dmp_segments`, granted by LinkedIn on request), authorized by a member with a role other than Viewer on the ad account. Config: `adAccountId`. Emails only. LinkedIn has no replace-all, so Herald sends only the difference from what it sent before. Matching takes 24 to 48 hours, and an audience needs at least 300 matched members to deliver.

**Amazon Ads.** Not synced and no CSV format is available: Amazon's hashed customer lists go through Amazon Ads Data Manager, which needs manager account access and an approved Amazon Ads API application. It is on the roadmap.

### Common errors

| Message | Cause | Fix |
|---|---|---|
| `Meta: <message>`, `Google Ads: <message>` or `LinkedIn: <message>` | Shown on the audience as its last error: the platform refused the upload | Check the account's access and terms for customer lists |
| `Sign-in failed: <reason>` or `The credentials are not JSON` | The credentials can't sign in | Paste current credentials |
| `Add 1 to 10 audiences` or `Each audience needs a segment` | Saving the integration: audiences missing | Add an audience with a segment |

## Troubleshooting

- **A webhook keeps re-sending a batch.** Your endpoint must answer 2xx within 10 seconds.
- **The CSV request answers 403.** The key lacks the `exports.read` scope.
- **The CSV request answers 400.** The range is longer than 31 days.
- **An audience stays empty or small.** Check the pair's last error, then the platform's minimum matched size above.
