# Fix conversion tracking with an agent

The recipe a coding agent follows to take a site from a leaking Conversion Leak Report to server-side verified: scan, install the tag, forward, verify, rescan.

A coding agent with the [Zernio MCP server](/mcp) runs these steps itself. Each step names its MCP tool; the REST call is the same operation.

## Before you start

- A Zernio API key, or the MCP server signed in. Ad features need the Ads add-on, included with usage-based billing.
- Access to the website's code, and a login to each ad account the site advertises on.
- The Zernio agent skill installs this recipe as `fix-conversion-tracking`: the Claude Code plugin (`/plugin install zernio@zernio`), or `npx clawhub@latest install mikipalet/zernio-api`.

## Step 1: Scan the site

Run the [Conversion Leak Report](/conversion-audit/audit-conversion-tracking) on the homepage and keep the score, each network's `status` and its pixel `ids` (`conversion_audit_audit_conversion_tracking`).

```bash
curl "https://zernio.com/api/v1/conversion-audit?url=brand.com" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
```

A network whose `status` is `good` is done. The rest are the ones to fix.

## Step 2: Connect the ad accounts

List the profile's ad connections with [List accounts](/accounts/list-accounts) (`accounts_list`, platform `metaads`, `googleads`, `tiktokads` and so on).

For a network that is missing, [Connect ads](/connect/connect-ads) (`connect_ads`) returns an `authUrl` that the ad account's owner opens in a browser. Google Analytics 4 connects through [Get the Google Analytics connect URL](/connect/get-google-analytics-connect-url) instead.

## Step 3: Create the tracking site

First [list the tracking sites](/conversions/list-tracking-sites) (`conversions_list_tracking_sites`) and reuse one whose `domains` hold the scanned host: a second site means a second tag on the page.

Otherwise create it with [Create a tracking site](/conversions/create-tracking-site) (`conversions_create_tracking_site`).

```bash
curl -X POST "https://zernio.com/api/v1/tracking-sites" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Idempotency-Key: 7f3c2a8e-1b4d-4c9a-9e2f-5a6b7c8d9e0f" \
  -H "Content-Type: application/json" \
  -d '{"profileId": "66a1f0c2a4b9d3e8f1a2b3c4", "url": "https://brand.com"}'
```

A connected Shopify, WordPress, Wix or Webflow store takes `storeAccountId` instead, and Zernio installs the tag through the store's app: skip step 4.

## Step 4: Install the tag

Add the queue line and the site's `install.snippet` before `</head>` on every page, then send each conversion with the same id your pixel uses, as on [The tracking script](/products/server-side-tracking/script):

```js
zernio('track', 'Purchase', { eventId: 'order_1042', value: 129.99, currency: 'USD' });
fbq('track', 'Purchase', { value: 129.99, currency: 'USD' }, { eventID: 'order_1042' });
```

GA4 and Elevar ecommerce events already pushed to the `dataLayer` are read without code.

## Step 5: Forward to each network

For each network to fix, list its destinations with [List conversion destinations](/conversions/list-ad-conversion-destinations) (`conversions_list_ad_conversion_destinations`). Pick the one the page runs:

| Network | Destination |
|---|---|
| Meta | The pixel with the id the scan read |
| TikTok | `pixel:<code>` for the pixel the scan read |
| Google Ads, LinkedIn | A conversion action or rule per conversion |
| Google Analytics 4 | The `G-` measurement id the scan read, on a page without an `AW-` tag |

Save it with [Add a forwarding rule](/conversions/create-forwarding-rule) (`conversions_create_forwarding_rule`).

```bash
curl -X POST "https://zernio.com/api/v1/events/forwarding-rules" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"profileId": "66a1f0c2a4b9d3e8f1a2b3c4", "accountId": "66a1f0c2a4b9d3e8f1a2b3c5", "destinationId": "1234567890123456", "sources": ["web"]}'
```

On Google Ads and LinkedIn, save one rule per conversion action with its `eventNames`, such as `["Purchase"]`.

## Step 6: Verify the events arrive

Deploy, open the site in a normal browser, accept cookies and make a test conversion. Then check, in order:

1. [Get a tracking site](/conversions/get-tracking-site) (`conversions_get_tracking_site`): `setup.status` is `ready` after the first visit.
2. [List events](/conversions/list-events) (`conversions_list_events`, `source: web`): the conversion is there, with a `sent` delivery per network.
3. [Get today's tracking overview](/conversions/get-events-overview) (`conversions_get_events_overview`): each forwarding rule shows `sentToday` and any `lastError`.

## Step 7: Rescan

Run step 1 again. A network turns `status: good` with `serverSideVerified: true` once its destination accepted the site's events in the last 7 days, and the score rises. Until then it stays `warn`, with `serverSideStatus: likely`.

## How it behaves

- **Matched to the page's tag.** Meta, TikTok and GA4 verify only when the destination is the pixel or measurement id the page runs. A page with an `AW-` tag verifies with any Google Ads delivery from the site, so forward to the account behind that tag; GA4 deliveries alone never verify it.
- **Only the Zernio tag is verified.** When the scan also sees another server-side tool, such as a server Tag Manager container, it cannot tell which one delivers, and the network stays `likely`.
- **Bots never count.** A headless browser is flagged as a bot, so its conversions are never stored or forwarded. Test in a real browser.
- **Consent first.** Without ad storage consent, a conversion is stored without identifiers and never forwarded. See [Consent](/products/server-side-tracking/consent).

## If it fails

| Error | Cause | Fix |
|---|---|---|
| `403` `Ads add-on required` | The account has no ads access | Turn on the Ads add-on, or move to usage-based billing |
| `409` `store_already_tracked` | The store already has a site | Use the site in `details.siteId` |
| `409` on the forwarding rule | The profile already forwards to that destination | Keep the existing rule |
| `setup.status` stays `pending` | No real visit has loaded the tag yet | Check the page source for the snippet, then visit the page in a normal browser |
| No event in `GET /v1/events` | No ad storage consent, a bot visit, or a host outside the site's `domains` | Accept cookies in a normal browser, or add the host with `PATCH /v1/tracking-sites/{siteId}` |
| Rescan still `likely` | The destination is not the pixel on the page, nothing reached it in 7 days, or another server-side tool is on the page | Forward to the page's own pixel id and send a test conversion |

## Related

- [Audit conversion tracking](/conversion-audit/audit-conversion-tracking)
- [Create a tracking site](/conversions/create-tracking-site)
- [Add a forwarding rule](/conversions/create-forwarding-rule)
- [List events](/conversions/list-events)
- [Test and verify](/products/server-side-tracking/verify)