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

# Custom event value & formulas in Upstack

> Override the value sent with a custom event — send profit, margin, a fixed amount, or a custom formula so ad platforms optimize on the value that matters to you.

By default, Upstack forwards the event's own value to your destinations. You can **override** it so your ad platforms optimize on the value that matters to you — profit instead of revenue, a fixed lead value, or a number you compute yourself. This is the foundation of value‑based bidding.

You set this while creating or editing a mapping (see [Global event mappings](/guides/custom-events/global-event-mappings) and [Destination event mappings](/guides/custom-events/destination-event-mappings)). Turn on **Override event value**, then choose under **Set value to**.

## Value options

| Option                      | What it sends                                               | Requirements                         |
| --------------------------- | ----------------------------------------------------------- | ------------------------------------ |
| **Event value**             | The value already on the event (the default — no override). | —                                    |
| **Net Revenue**             | Revenue after discounts and refunds.                        | Shopify order data · purchase events |
| **CM1 (Gross Margin)**      | Net revenue minus product cost (COGS).                      | Shopify order data · purchase events |
| **CM2 (After Fulfillment)** | CM1 minus shipping, handling, and fees.                     | Shopify order data · purchase events |
| **Fixed value**             | A set amount you choose (e.g. a flat lead value).           | —                                    |
| **Custom formula**          | A value you build yourself.                                 | See below                            |

The revenue and profit presets are computed per order from your [cost settings](/get-started/cost-settings). They require Shopify order data and apply to purchase events. Value‑bearing events like `add_to_cart` can use **Net Revenue** (revenue only — no cost).

<Note>
  Cost- and revenue-based options need Shopify order data. On non‑Shopify accounts you can still use **Fixed value** or a **Custom formula** over your own `data.*` fields.
</Note>

## Custom formula

The formula builder has two modes:

* **Simple builder** — start with a value, then adjust it step by step (e.g. **Event value × 0.7**). Each part is a **Metric** (a known measure), a **Field** (a custom event field, entered as `data.fieldName`), or a **Number**. Steps apply left to right, like a calculator.
* **Advanced** — write the raw formula directly, with autocomplete for variables. Use `+ − * /` and parentheses.

### Operands you can reference

| Operand                                                                                           | Meaning                                                | Available on     |
| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------ | ---------------- |
| `data.value`                                                                                      | The value already on the event.                        | Every event      |
| `data.<field>`                                                                                    | Any custom field on the event (e.g. `data.leadValue`). | Every event      |
| `orders.gross_revenue`                                                                            | Gross revenue before discounts and refunds.            | Shopify purchase |
| `orders.net_revenue`                                                                              | Revenue after discounts and refunds.                   | Shopify purchase |
| `orders.subtotal`, `orders.tax`, `orders.discount_amount`, `orders.refund_amount`, `orders.units` | Order revenue components.                              | Shopify purchase |
| `orders.cogs`, `orders.other_cogs`                                                                | Cost of goods sold.                                    | Shopify purchase |
| `orders.shipping_cost`, `orders.handling_cost`, `orders.other_fulfillment_cost`                   | Fulfillment costs.                                     | Shopify purchase |
| `orders.gateway_cost`, `orders.other_transaction_cost`                                            | Transaction/gateway fees.                              | Shopify purchase |

Cost operands (`orders.cogs`, `orders.shipping_cost`, …) are only available on purchase events, where full order cost data exists.

### Examples

| Goal                                     | Formula                            |
| ---------------------------------------- | ---------------------------------- |
| Send 70% of the event value              | `data.value * 0.7`                 |
| Send profit (revenue minus product cost) | `orders.net_revenue - orders.cogs` |
| Subtract a flat fee from the value       | `data.value - 15`                  |
| Scale a custom lead value                | `data.leadValue * 0.4`             |

<Note>
  **A missing field skips the formula — it doesn't zero your value.** If an event doesn't carry a field your formula references (say `data.leadValue` on an event that didn't send it), Upstack skips the override and forwards the event's own value instead, so a missing field never overwrites a real value with `0`. A field that *is* present but genuinely `0` is used as `0`. Still, reference only fields your events reliably send, so the formula applies when you expect it to.
</Note>

## Related

<CardGroup cols={2}>
  <Card title="Global event mappings" icon="globe" href="/guides/custom-events/global-event-mappings">
    Create a mapping once and send it to every destination.
  </Card>

  <Card title="Cost settings" icon="calculator" href="/get-started/cost-settings">
    Configure the costs behind Net Revenue, CM1, and CM2.
  </Card>

  <Card title="Custom events overview" icon="bolt" href="/guides/custom-events/how-to-create-custom-event-triggers">
    What custom events are and when to use them.
  </Card>

  <Card title="Approve Meta custom events" icon="check" href="/guides/facebook-ads/how-to-approve-facebook-meta-custom-events">
    Approve and verify custom events in Meta Events Manager.
  </Card>
</CardGroup>
