> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tyrionurl.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Tracking Conversions

> Send purchase and lead events from your landing pages back to TyrionURL to measure true A/B test ROI.

## Overview

Click counts tell you which A/B test variant attracted more visitors. Conversion tracking tells you which variant actually drove revenue or leads. This guide covers how to send conversion events from your partner site to TyrionURL using your API key.

***

## Prerequisites

Before setting up conversion tracking:

1. ✅ You have [created an A/B test](/ab-testing/setup) on a TyrionURL short link
2. ✅ You have [generated an API key](/ab-testing/api-keys) in Settings
3. ✅ You have access to add code to the landing page or checkout confirmation page on your partner site

***

## How Conversion Tracking Works

```
User clicks TyrionURL short link
     ↓
TyrionURL assigns them to Variant A or B
     ↓
User lands on the variant's destination page
     ↓
User completes a purchase / form / sign-up
     ↓
Partner site sends conversion event to TyrionURL API
     ↓
TyrionURL attributes the conversion to the variant
     ↓
Data appears in your A/B test analytics
```

***

## Sending a Conversion Event

On your confirmation page (order thank-you page, lead form success page, etc.), make a server-side API call to TyrionURL:

<CodeGroup>
  ```javascript Node.js theme={null}
  const response = await fetch('https://api.tyrionurl.com/api/abtest/convert', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${process.env.TYRIONURL_API_KEY}`
    },
    body: JSON.stringify({
      shortCode: 'your-short-code',   // The short code of the A/B tested link
      eventType: 'purchase',          // 'purchase' | 'lead' | 'signup'
      revenue: 49.99,                 // Optional: revenue amount in your currency
      currency: 'USD',                // Optional: ISO 4217 currency code
      metadata: {                     // Optional: any additional context
        orderId: 'ORD-12345',
        productId: 'prod-abc'
      }
    })
  });
  ```

  ```python Python theme={null}
  import requests
  import os

  response = requests.post(
      'https://api.tyrionurl.com/api/abtest/convert',
      headers={
          'Content-Type': 'application/json',
          'Authorization': f'Bearer {os.environ["TYRIONURL_API_KEY"]}'
      },
      json={
          'shortCode': 'your-short-code',
          'eventType': 'purchase',
          'revenue': 49.99,
          'currency': 'USD',
          'metadata': {
              'orderId': 'ORD-12345'
          }
      }
  )
  ```

  ```php PHP theme={null}
  $response = file_get_contents('https://api.tyrionurl.com/api/abtest/convert', false, stream_context_create([
      'http' => [
          'method' => 'POST',
          'header' => [
              'Content-Type: application/json',
              'Authorization: Bearer ' . getenv('TYRIONURL_API_KEY')
          ],
          'content' => json_encode([
              'shortCode' => 'your-short-code',
              'eventType' => 'purchase',
              'revenue' => 49.99,
              'currency' => 'USD'
          ])
      ]
  ]));
  ```
</CodeGroup>

<Info>
  Always send conversion events from **server-side code** (not client-side JavaScript) to protect your API key from being exposed in browser source code.
</Info>

<Warning>
  TODO: Needs Product Verification — Confirm the exact conversion API endpoint path, request schema, and supported `eventType` values with the TyrionURL engineering team.
</Warning>

***

## Conversion Event Fields

| Field       | Type   | Required | Description                                                     |
| ----------- | ------ | -------- | --------------------------------------------------------------- |
| `shortCode` | string | Yes      | The short code of the A/B tested link that referred the visitor |
| `eventType` | string | Yes      | Type of conversion: `purchase`, `lead`, or `signup`             |
| `revenue`   | number | No       | Revenue value associated with the conversion                    |
| `currency`  | string | No       | ISO 4217 currency code (e.g., `USD`, `INR`, `EUR`)              |
| `metadata`  | object | No       | Any additional key-value pairs for your own reference           |

***

## Passing the Short Code Through Your Funnel

For TyrionURL to attribute the conversion to the correct variant, your landing page needs to know which short code referred the visitor. The recommended approach is to append the short code as a URL parameter when linking from TyrionURL:

**Example destination URL in Variant A:**

```
https://yourstore.com/landing?ref=tyrion&sc=summer-sale
```

Your landing page reads the `sc` parameter and passes it through your checkout flow (via a hidden form field or session cookie) to the confirmation page, where the conversion event is sent.

***

## Viewing Conversion Data

After conversion events are flowing, view results in your link's A/B test analytics panel:

| Metric                      | Description                                      |
| --------------------------- | ------------------------------------------------ |
| **Conversions per variant** | Count of conversion events per destination URL   |
| **Revenue per variant**     | Sum of revenue values attributed to each variant |
| **Conversion rate**         | Conversions ÷ Clicks for each variant            |
| **Revenue per click**       | Total revenue ÷ Total clicks per variant         |

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/docs-tyrionurl/images/ab-test-conversions.png" alt="A/B test results with conversion and revenue data" />
</Frame>

***

## Best Practices

<Check>Start sending conversion events from day one of an A/B test — retroactive attribution isn't possible for past clicks.</Check>
<Check>Use the `metadata` field to store order IDs so you can cross-reference TyrionURL conversions with your own order management system.</Check>
<Check>Only fire the conversion event on confirmed completions (e.g., order confirmation page) — not on button clicks or form starts.</Check>

***

## Related Pages

<CardGroup cols={2}>
  <Card title="A/B Testing Setup" icon="flask" href="/ab-testing/setup">
    Configure your split test before tracking.
  </Card>

  <Card title="API Keys" icon="key" href="/ab-testing/api-keys">
    Generate and manage your integration credentials.
  </Card>
</CardGroup>
