# Revenue tracking

URL: https://docs.ablyft.com/developers/tracking-and-events/revenue-tracking/

> Send order values to ABlyft and keep outliers from distorting your results.



A **revenue goal** measures money instead of a yes/no conversion, for example the order value. Your website sends the
value with one JavaScript call. ABlyft then compares the revenue between variations.

## Step 1: Create the goal in ABlyft

1. Go to **Targeting & Goals → Goals** and create a goal.
2. Choose the type **Revenue** ("Trigger a revenue value via JavaScript"). The measurement type is set to **Value**
   automatically.
3. Check the **API Name**, for example `purchase`.
4. Enter the **Currency sign**, for example `€`. It is required and used to display values.
5. Optional: choose a **Value filter type**, see [Value filters](https://docs.ablyft.com/guides/goals-and-measurement/goal-types/#value-filters).
6. In **Statistic Settings**, choose the counting method and winning direction, then save.
7. [Assign the goal to your experiment](https://docs.ablyft.com/guides/goals-and-measurement/configure-goals/#assign-goals-to-an-experiment).

## Step 2: Send the revenue

Call this on your order confirmation, with the real order value.

```html
<script>
window['ablyft'] = window['ablyft'] || [];
window['ablyft'].push({
    eventType: 'revenue',
    eventName: 'purchase',
    eventValue: 49.9
});
</script>
```

All push parameters are listed in the [`push()` reference](https://docs.ablyft.com/developers/reference/javascript-api/push/#revenue). The
`eventName` must match the **API Name** of the goal exactly, otherwise the call is ignored silently.

Use a number, not a string: `49.9`, not `"49,90 €"`. Send the same kind of value on every call (for example always
the net or always the gross order value), and decide this before the experiment starts.

### Take the value from your page

On a server-rendered page, print the value into the call:

```html
<script>
window['ablyft'] = window['ablyft'] || [];
window['ablyft'].push({
    eventType: 'revenue',
    eventName: 'purchase',
    eventValue: 129.00 // output the order total here
});
</script>
```

With a data layer, read the value from the entry (here a GA4-style `purchase` event):

```js
ablyftTools.watchDataLayerEntry('purchase', (entry) => {
  window.ablyft = window.ablyft || [];
  window.ablyft.push({
    eventType: 'revenue',
    eventName: 'purchase',
    eventValue: Number(entry.ecommerce.value)
  });
});
```

`ablyftTools` is available in the project JS code (**Settings → Project Settings → Project Level Codes**). See
[Custom JavaScript](https://docs.ablyft.com/developers/application-integration/custom-javascript/) and [Data layer events](https://docs.ablyft.com/developers/tracking-and-events/datalayer-events/).

## Counting method

Choose the counting method in the goal, see [Counting method](https://docs.ablyft.com/guides/goals-and-measurement/goal-types/#counting-method).
With **Every**, a visitor with three orders contributes three values.

> **Avoid double counting:** Make sure the call runs once per order. A confirmation page that is reloaded, or a data layer event that fires twice,
> would send the revenue twice when the counting method is **Every**. Protect the call, for example with a flag in
> `sessionStorage` for the order ID.

## Value filters

A value filter caps outliers such as one very large order when results are calculated. Types, examples and effects are
described in [Value filters](https://docs.ablyft.com/guides/goals-and-measurement/goal-types/#value-filters).

## Check that it works

1. Complete a test order in a [preview](https://docs.ablyft.com/guides/experiments/preview-and-qa/) of your experiment, with
   [debug mode](https://docs.ablyft.com/developers/debugging/preview-and-live-log/#debug-mode) on. The console logs `Triggered GOAL "<name>" (revenue)`.
2. Check the **Live Log** of your project for the incoming event.
3. Open the experiment results and compare the revenue with your shop system after some days. See
   [Verify measurement](https://docs.ablyft.com/guides/goals-and-measurement/verify-measurement/).

## Next steps

- [Custom goals](https://docs.ablyft.com/developers/tracking-and-events/custom-goals/): Conversions without a revenue value.
- [ablyft.push()](https://docs.ablyft.com/developers/reference/javascript-api/push/): All push parameters.
- [Goal types](https://docs.ablyft.com/guides/goals-and-measurement/goal-types/): Compare all four types.

