# Meta

CLItrail sends each attributed install to the Meta Conversions API with the visitor's Meta browser and click IDs, so Meta can optimise ads for installs.

## Set it up

1. Generate an access token
  In Meta Events Manager, choose your pixel, open **Settings**, find **Conversions API** and choose **Generate access token**. The link is visible only to people with developer access to the business.
2. Add the destination
  Enter the pixel ID and the access token. Optionally rename the events (defaults `CLIInstall` and `CLIFirstRun`), set Limited Data Use, and add a value and currency.
3. Send a test event
  Copy the test code from **Events Manager → your pixel → Test events**. It starts with `TEST`.
4. Go live
  Confirm Meta's terms and your notice duties, and [verify your domain](https://clitrail.com/docs/domain-verification) first.

> Warning
> 
> Meta does not drop events sent with a test code: they flow into Events Manager and can be used for targeting and measurement. CLItrail's test uses the separate event name `CLItrailConnectionTest` so it never counts as an install. Do not optimise for that event.

## What is sent

A form POST to `https://graph.facebook.com/v26.0/<pixel id>/events` with a `data` field holding up to 1,000 events and an `access_token` field. The token travels in the body, never in the URL.

```json
{
  "event_name": "CLIInstall",
  "event_time": 1790172131,
  "event_id": "clt_f399d6357f61bcf15f9370c69a41662457de8a05",
  "action_source": "other",
  "user_data": {
    "external_id": [
      "a68e7a64d91bfe305bd5c2a9f285ca38dec72a8a0d4036ee28a92bc72fb773ac"
    ],
    "fbc": "fb.1.1790171920120.YOUR_FBCLID",
    "fbp": "fb.1.1790170011032.1098115397"
  },
  "custom_data": { "value": 1, "currency": "USD" }
}
```

- **`action_source` is `other`.** The install happened in a terminal, and Meta asks advertisers not to label such actions `website`.
- **`fbc`** comes from the `_fbc` cookie, dated by the click time it carries, or is built as `fb.1.<visit time in ms>.<fbclid>` when the visit's URL had an `fbclid`. The attribution policy picks the most recent or earliest click, and the same for `fbp`. `fbc` and `fbp` are sent unhashed, as Meta requires, and malformed cookie values are left out.
- **`external_id`** is a SHA-256 hash of a pseudonymous installation ID. No email, name or other personal data is sent.
- An install needs `fbc` or `fbp` on a touch; otherwise nothing is sent to Meta.
- **Time limits.** Meta rejects a whole request when any event is more than 7 days old, so queued events expire one hour before that.
- **Deduplication.** Meta keeps the first event with the same `event_id` and `event_name` within 48 hours. Retries stop before 48 hours.
- **Limited Data Use.** Off, on with Meta deciding by the visitor's location (`LDU`, country 0, state 0), or on for California (country 1, state 1000).
