# Configuration

The Trybe integration tracks events on both the browser and server side. The browser SDK fires standard e-commerce events via the Trybe pixel. The server sends the `Purchase` event to the Trybe Attribution API with the visitor's click ID attached.

***

### Browser-Side Events

The EdgeTag browser SDK calls `window._trybe.track*` methods after the Trybe pixel is loaded and `window._trybe.vid` is set. The `vid` is populated by the pixel and identifies the visitor for attribution.

If `window._trybe` is not present, or `window._trybe.vid` is not yet set (pixel still loading), all browser-side calls are silently skipped.

#### Supported Events

| EdgeTag Event      | Trybe Method             |
| ------------------ | ------------------------ |
| `ViewContent`      | `trackProductViewed`     |
| `AddToCart`        | `trackAddToCart`         |
| `InitiateCheckout` | `trackCheckoutStarted`   |
| `Purchase`         | `trackCheckoutCompleted` |

{% hint style="info" %}
`PageView`, `AddShippingInfo`, `AddPaymentInfo`, and custom events are not mapped to any Trybe pixel method and are ignored on the browser side.
{% endhint %}

***

#### ViewContent

Triggered when a visitor views a product page.

| Trybe Param   | EdgeTag Source                                |
| ------------- | --------------------------------------------- |
| `vid`         | `window._trybe.vid`                           |
| `productId`   | `data.contents[0].id` → `data.productId`      |
| `productName` | `data.contents[0].title` → `data.productName` |
| `price`       | `data.contents[0].item_price` → `data.price`  |
| `currency`    | `data.currency` (default: `USD`)              |
| `productUrl`  | `data.productUrl` → `window.location.href`    |
| `imageUrl`    | `data.contents[0].imageUrl` → `data.imageUrl` |

**Example:**

```js
edgetag('tag', 'ViewContent', {
  currency: 'USD',
  contents: [
    {
      id: 'sku_001',
      title: 'Example Product',
      item_price: 49.99,
      imageUrl: 'https://yourstore.com/images/sku_001.jpg'
    }
  ],
  productUrl: 'https://yourstore.com/products/example'
})
```

***

#### AddToCart

Triggered when a visitor adds a product to their cart.

| Trybe Param   | EdgeTag Source                                               |
| ------------- | ------------------------------------------------------------ |
| `vid`         | `window._trybe.vid`                                          |
| `productId`   | `data.contents[0].id` → `data.productId`                     |
| `productName` | `data.contents[0].title` → `data.productName`                |
| `quantity`    | `data.contents[0].quantity` → `data.quantity` (default: `1`) |
| `price`       | `data.contents[0].item_price` → `data.price`                 |
| `currency`    | `data.currency` (default: `USD`)                             |

**Example:**

```js
edgetag('tag', 'AddToCart', {
  currency: 'USD',
  contents: [
    { id: 'sku_001', title: 'Example Product', quantity: 1, item_price: 49.99 }
  ]
})
```

***

#### InitiateCheckout

Triggered when a visitor begins the checkout process.

| Trybe Param | EdgeTag Source                            |
| ----------- | ----------------------------------------- |
| `vid`       | `window._trybe.vid`                       |
| `cartValue` | `data.value` (default: `0`)               |
| `currency`  | `data.currency` (default: `USD`)          |
| `itemCount` | `data.contents.length` → `data.itemCount` |

**Example:**

```js
edgetag('tag', 'InitiateCheckout', {
  value: 99.99,
  currency: 'USD',
  contents: [
    { id: 'sku_001', quantity: 2, item_price: 49.99 }
  ]
})
```

***

#### Purchase (Browser)

Triggered on the order confirmation page alongside the server-side attribution call.

| Trybe Param  | EdgeTag Source                   |
| ------------ | -------------------------------- |
| `vid`        | `window._trybe.vid`              |
| `orderId`    | `data.orderId`                   |
| `orderValue` | `data.value` (default: `0`)      |
| `currency`   | `data.currency` (default: `USD`) |

***

### Server-Side Events

EdgeTag sends the `Purchase` event to the Trybe Attribution API from the edge. All other events are silently dropped server-side.

#### Purchase

**API endpoint:** `POST https://jointrybe.com/attribution/v1/orders`

| Trybe Field | EdgeTag Source                          | Notes                                                |
| ----------- | --------------------------------------- | ---------------------------------------------------- |
| `apiKey`    | `TRYBE_API_KEY`                         | Your Trybe API key                                   |
| `orderId`   | `data.orderId`                          | Falls back to EdgeTag `eventId` if not set           |
| `value`     | `data.value`                            | Order total; defaults to `0`                         |
| `currency`  | `data.currency`                         | Defaults to `USD`                                    |
| `vid`       | `?trybe=` click ID or `ugc_vid_` cookie | **Mandatory for attribution** — see resolution below |
| `email`     | `user.email`                            | Included when available; optional                    |
| `orderTime` | `payload.timestamp`                     | ISO 8601 UTC; falls back to current time             |
| `items`     | `data.contents`                         | Array of `{ id, quantity, item_price }`; optional    |

**Example:**

```js
edgetag('tag', 'Purchase', {
  orderId: 'order_12345',
  value: 99.99,
  currency: 'USD',
  contents: [
    { id: 'sku_001', quantity: 2, item_price: 49.99 }
  ]
})
```

#### Visitor ID Resolution

The `vid` field is resolved in this order:

1. **`?trybe=CLICK_ID`** — the affiliate click ID captured from the landing URL and stored at the edge for the session. This is the primary attribution signal.
2. **`ugc_vid_{storeId}` cookie** — the visitor cookie set by the Trybe pixel in the browser. Used as a fallback when no click ID is present.

{% hint style="warning" %}
The click ID is mandatory for Trybe to attribute the order to an affiliate or influencer. If neither the click ID nor the cookie is found when a `Purchase` fires, the server-side attribution call is skipped entirely.
{% endhint %}
