Revenue on Custom Events

A newer way to track revenue exists

A vs B now has a dedicated purchase event, avsb.track.purchase. It has built-in deduplication and five revenue metrics on the Results page, plus refund tracking for connected stores and server-side integrations. See Tracking Revenue for the current recommended approach. This page documents the older avsb.track.event(key, { revenue }) pattern, which still works.

A variation is one specific version being tested: the control, or a challenger. When you pass a revenue amount with a custom event, A vs B can calculate the estimated revenue impact of your experiment. It shows not just whether one variation converted more, but how much more money it generated. This is the most direct way to connect your A/B tests to business outcomes.

How revenue tracking works

Revenue tracking is an optional extension of custom events. When you call avsb.track.event(), you can pass a second argument containing a revenue property. The value should be a plain number representing the transaction amount in your primary currency.

JavaScript
avsb.track.event('purchase_completed', { revenue: 49.99 });
JavaScript1 line

The first argument is the metric's event key, the text you typed when you created the metric. A vs B stores this value alongside the conversion record. When you view your experiment results, the Results page uses the stored revenue figures to calculate:

  • Revenue per visitor: total revenue divided by total visitors for each variation.
  • Revenue Impact: the estimated additional revenue generated by the winning variation compared to the control, projected over the full experiment traffic.
  • Average Order Value (AOV): total revenue divided by the number of converting visitors for each variation.

Code examples

E-commerce purchase

Track the revenue from a completed purchase. Fire this after the server confirms the order. Read the total from your order confirmation page, or from the API response.

Reading revenue from the page:

JavaScript
// Read the order total from a data attribute or hidden fieldvar totalEl = document.getElementById('order-total');var orderTotal = parseFloat(totalEl?.dataset.value ?? '');avsb.track.event('purchase_completed', { revenue: orderTotal });
JavaScript5 lines

Reading revenue from an API response:

JavaScript
var cartData = JSON.stringify({ items: [{ sku: 'SKU-001', quantity: 1 }] });fetch('/api/checkout', { method: 'POST', body: cartData })  .then(function(response) { return response.json(); })  .then(function(data) {    if (data.success) {      avsb.track.event('purchase_completed', { revenue: data.order.total });    }  });
JavaScript9 lines

SaaS trial conversion

Track when a free trial converts to a paid subscription. Pass the monthly or annual plan value as revenue.

JavaScript
// When the user upgrades to a paid planvar planValue = 29.00; // monthly plan priceavsb.track.event('plan_selected', { revenue: planValue });
JavaScript4 lines

Dynamic revenue from a data layer

JavaScript
// Reading from a GTM-style dataLayer pushwindow.dataLayer = window.dataLayer || [];window.dataLayer.push({  event: 'purchase',  transactionTotal: 79.99});// In your A vs B tracking code, read from the dataLayervar lastPurchase = window.dataLayer  .filter(function(e) { return e.event === 'purchase'; })  .pop();// dataLayer entries are somebody else's data, so check the field before sending itif (typeof lastPurchase?.transactionTotal === 'number') {  avsb.track.event('purchase_completed', { revenue: lastPurchase.transactionTotal });}
JavaScript16 lines

Average Order Value calculation

Average Order Value (AOV) is calculated per variation as:

Plain text
AOV = Total Revenue / Number of Converting Visitors
Plain text1 line

A high AOV in one variation does not necessarily mean that variation is better overall: it means the visitors who converted spent more on average. A variation could have a lower conversion rate but a higher AOV, meaning fewer visitors bought but each one spent more. The Revenue Impact card on the results page accounts for both the conversion rate and the AOV together.

When to use revenue tracking

Revenue tracking is most useful when:

  • You are running an e-commerce site. You want to know whether a design change drives more purchases and more revenue, not just more clicks.

  • You are testing pricing or plan presentation on a SaaS product. You want to compare how variations affect the revenue value of conversions, not just the conversion rate.

  • You have a high cart abandonment problem. You want to know whether a checkout redesign generates more revenue per visitor, even when the raw conversion-rate improvement looks small.

Important notes

Revenue is stored on first conversion only

A vs B records at most one conversion per visitor per metric. Only the revenue value from the first avsb.track.event() call is stored. If a visitor buys more than once during the experiment, only the first purchase counts.

Pass a plain number

The revenue value must be a plain JavaScript number: for example 49.99. Do not pass a formatted string like '$49.99' or '49,99'. These will not be parsed correctly and the revenue data will be lost.

Was this helpful?