# Set up conversions with AI assistants

Give Claude Code, Cursor, Codex or Lovable the rules to add Zernio conversions: the site tag, a server-side track() call with the same event id, and a test.

Coding assistants read an `AGENTS.md` file at the root of your repository. Paste the block below into it, and every assistant adds Zernio conversions the same way: tag, server call, shared event id, test.

## Before you start

- A Zernio API key and the profile your conversions belong to. Sending conversions needs the Ads add-on.
- A [tracking site](/products/server-side-tracking/install) for your website, and at least one ad account it [forwards to](/products/server-side-tracking/ad-accounts).
- Optional: the [Zernio MCP server](/mcp) connected to the assistant, so it reads your setup and your site's tag itself.

## Step 1: Add the block to AGENTS.md

Copy this into `AGENTS.md` (Claude Code also reads `CLAUDE.md`), and replace `<PROFILE_ID>` with your profile id.

```markdown
## Zernio conversions

This project reports conversions (purchases, leads, sign-ups) to ad platforms through Zernio. When you add or change one:

1. Site tag: every page loads the Zernio tag inside <head>. Copy the exact lines from the Zernio dashboard (Ads, Conversions, the site, Install) or from the Zernio MCP tool `conversions_get_install_snippet` with stack `site_tag`. Never write the tag, site key or domain yourself.
2. Browser event: right after the conversion, call `zernio('track', 'Purchase', { eventId, value, currency })`, with an eventId built from the record, such as `'order_' + order.id`. The tag loads async, so put this line above it in <head> to keep a call made before it loads: `<script>if (typeof window.zernio !== 'function') window.zernio = function () { (window.zernio.q = window.zernio.q || []).push(arguments); };</script>`
3. Server event: once the server confirms the same conversion (payment succeeded, lead saved), call `track()` with the same eventId, so ad platforms count it once. Every option: https://docs.zernio.com/products/conversions-api/track
   - Node.js, `@zernio/node` 0.2.1904 or later: `await zernio.track('Purchase', { profileId, eventId, value, currency, user: { email, ip, userAgent } })`
   - Python, `zernio-sdk` 1.4.2167 or later: `zernio.track("Purchase", profile_id=profile_id, event_id=event_id, value=value, currency=currency, user={"email": email, "ip": ip, "user_agent": user_agent})`
4. Keys: the SDK reads the API key from the ZERNIO_API_KEY environment variable. Never commit it or send it to the browser. The profile id is <PROFILE_ID>.
5. Data: send email and phone in plain text, since Zernio hashes them per platform and refuses hashed values. Send value in currency units, not cents.
6. Names: the site tag forwards only Purchase, Lead and CompleteRegistration.
7. Test: use Send test event in the dashboard's Destinations section, the MCP tool `conversions_send_test_event`, or `testCode` on `track()` (`test_code` in Python). Test events are not stored.

Guide: https://docs.zernio.com/products/conversions-api/ai-assistant
```

## Step 2: Ask the assistant

Ask it to "add Zernio conversion tracking for purchases". It installs the tag, then adds the `track()` call where your server confirms the order.

With the MCP server connected, the assistant takes the values from your account instead of asking you:

| MCP tool | What it returns |
|---|---|
| `conversions_get_setup` | The profile's tracking sites with their tag status and failed checks, its forwarding rules, and the next step |
| `conversions_get_install_snippet` | The code for one stack: `site_tag`, `node`, `python`, or the `lovable` prompt |
| `conversions_send_test_event` | Each destination's outcome for one test conversion |

## Step 3: Send a test event

Use **Send test event** in the dashboard, or ask the assistant to run `conversions_send_test_event`. Each destination reports **Sent in test mode**, **Refused** with the platform's reason, or why it took nothing.

From code, pass a test code: the event goes to each platform's test mode and is not stored.

<Tabs items={['Node.js', 'Python']}>
<Tab value="Node.js">
```typescript
import Zernio from '@zernio/node';

const zernio = new Zernio();

await zernio.track('Purchase', { profileId: '66a1f0c2a4b9d3e8f1a2b3c4', eventId: 'order_1042', value: 129.99, currency: 'USD', testCode: 'TEST12345' });
```
</Tab>
<Tab value="Python">
```python
from zernio import Zernio

zernio = Zernio()

zernio.track("Purchase", profile_id="66a1f0c2a4b9d3e8f1a2b3c4", event_id="order_1042", value=129.99, currency="USD", test_code="TEST12345")
```
</Tab>
</Tabs>

On Meta, use the code from Events Manager, **Test events**, to watch the event arrive there. Every `track()` option, its errors and retries are on [Send conversions with track()](/products/conversions-api/track).

## How it behaves

- **One id, one conversion.** The browser and server copies share the event id, so each platform keeps one. See [Count each conversion once](/products/server-side-tracking/deduplication).
- **The server copy survives blockers.** An ad blocker can stop the tag, never your server's `track()` call.
- **Some platforms record test events.** Google Ads, LinkedIn, Microsoft Ads, X, OpenAI and Taboola have no test mode and record a test event on the live account. Test against Meta, Pinterest, Reddit, Snapchat, GA4 or a TikTok pixel. See [Test mode and consent](/products/conversions-api/platforms#test-mode-and-consent).

## If it fails

| Error | Cause | Fix |
|---|---|---|
| The assistant writes its own tag | It has no access to your site's tag | Connect the MCP server, or paste the tag lines from the dashboard into `AGENTS.md` |
| Purchases count twice | The browser and server copies have different ids | Build both ids from the same record, such as `order_` plus the order id |
| `403` from `track()` | The account has no Ads add-on | Turn on the Ads add-on, or move to usage-based billing |
| No destination took the test event | No forwarding rule takes events from your backend | [Add a forwarding rule](/conversions/create-forwarding-rule), then send it again |

## Related

- [The tracking script](/products/server-side-tracking/script)
- [Send conversions with track()](/products/conversions-api/track)
- [Send events](/products/conversions-api/send)
- [Fix conversion tracking with an agent](/products/server-side-tracking/fix-with-agent)
- [Zernio MCP server](/mcp)
- [Test and verify](/products/server-side-tracking/verify)