Skip to main content


Optimizely Knowledge Base

Set up revenue tracking in Optimizely X Web

There are two versions of Optimizely
What version do you have?
Optimizely Classic
This is what the Optimizely Classic user interface looks like.
Optimizely X
This is what the Optimizely X user interface looks like.
. If you're using Optimizely Classic, check this article out instead.
relevant products:
  • Optimizely X Web Experimentation
  • Optimizely X Web Personalization

  • Add overall revenue to the metrics your experiment tracks
  • Implement the code snippet that calls Optimizely's revenue-tracking API

Optimizely can track total revenue from purchases or other events on your site, and attribute the amount to a specific experiment and variation. Once you add the required code to your site (usually on the purchase confirmation page) and add the revenue metric to your experiment, you’ll be able to see the revenue earned per visitorrevenue per paying visitorpurchases, and the total revenue earned per variation on your Results page.

Revenue usually won't be your primary metric, because unlike clicks or pageviews, revenue does not measure a specific, discrete action taken by your visitors. However, tracking revenue is a great way to tie your optimization efforts to the metrics that your company values most.

Revenue tracking in a nutshell

Revenue tracking goals are a type of custom event goal. A revenue goal tracks the monetary value of an event on your site and attributes that amount to a specific variation. You might use this to track how different variations impact total revenue and compare this to the number of purchase events, for instance.  

Key tips 

  • Add the revenue tracking code after the purchase is completed on the confirmation page
  • Unlike other goals in Optimizely, revenue is cumulative and not de-duplicated
  • Once the revenue code is implemented on a page, you can use it in multiple experiments

What to watch out for

  • The Optimizely snippet must be present on the page where you are tracking revenue.
  • ThevalueInCentsvariable is tracked in centsso $54.99 should be recorded as 54.99 x 100 = 5,499.
  • If your site accepts multiple currencies, convert all currencies to a single denomination before converting the valueInCents variable. 

Implement the Optimizely revenue tracking code

To track revenue, you’ll need to add a small snippet of code to your site to call Optimizely's revenue tracking API. As mentioned above, this code (an example of a custom event) typically goes on the purchase confirmation page, and it should look like this:

   window["optimizely"] = window["optimizely"] || [];

     "type": "event",
     "eventName": "trackRevenue",
     "tags": {
       "revenue": valueInCents

The 'eventName' parameter is required. You can give it whatever name you want. For example, if you wanted to track the event and name it 'purchases', you would simply type 'purchases' in place of 'trackRevenue' in the code block shown above.

The valueInCents variable represents the purchase amount, in cents (purchase amount*100). It is crucial that this value is passed to Optimizely in cents. Otherwise, your revenue totals will be incorrect. If you do not use U.S. currency, simply multiply the purchase amount in your currency by 100. For example, a purchase amount of 54.99 should be passed as 5499.

//pass the total purhase amount to a variable 
var value = ‘youDefineThisValue’;

// Revenue must be added in cents
var valueInCents = value * 100;

Note that you can choose which currency symbol is displayed for revenue metrics on the Optimizely Results Page.

Best practices

  • It’s best to track revenue after your checkout or billing detail form has been successfully submitted to avoid sending revenue totals for invalid purchases to Optimizely.
  • Avoid triggering the revenue goal on the click of a button. A visitor may click the button several times due to validation errors, and the revenue total would be sent to Optimizely on each click.
  • It is also crucial that this value is passed to Optimizely as an integer. Otherwise, your revenue totals will not be sent to Optimizely and will not show up on the Results page. If your site's revenue calculation code returns a floating point value such as 99.99999999999, you should truncate or round that value to 99.99 or 100. Choose a method that works best for your business needs.

In addition to tracking revenue, you can also report the purchase event as a conversion by creating a custom event. To track conversions, simply add a custom event for ‘purchases’ (or whatever value you have given your ‘eventName’) on the Results page.

Note that you do not have to add this event in order to track revenue. On the other hand, when you set up multiple custom events to i.e. track different types of revenue, be mindful about the fact that the default 'Overall revenue' global metric will cumulatively count in any value with the 'revenue' tag assigned to it, regardless of the event name.

Once you've implemented this code on your page, you won't need to make adjustments to it again. The same code can be re-used to track revenue for multiple experiments across the entire project.


Unlike most other metrics, the revenue metric is cumulative and is not de-duplicated based on the visitor’s unique user ID or another identifier like order ID. As such, revenue will be counted toward the variation total each time Optimizely receives a revenue amount.

To more accurately count how many transactions have been received by Optimizely, we recommend adding a page view event to the confirmation or thank you page where the revenue API call is located.  When this metric is set to count 'total conversions' you should have a better representation of how many times the revenue event was triggered or how many total transactions were made.  

Add the Overall Revenue metric to your experiment

The next step is to add the Overall Revenue metric to your experiment. This lets Optimizely know that you'll want to track revenue for this experiment.

  1. From your Campaigns dashboard, open your experiment and click Metrics.

  2. The Metrics panel will open. Find the custom event labeled "Overall Revenue" and click on it to add it to your experiment.

    By default, Overall Revenue is now your primary metric for this experiment. If your experiment calls for it, you can add other metrics to the experiment and select one of them as the primary metric (as we discussed earlier, in most cases Overall Revenue isn't the ideal choice for a primary metric).

  3. Click Save to save your metrics for this experiment, or click Revert to cancel your changes.

Congratulations - you've set up your experiment to track revenue!

Note Overall Revenue does not count conversions with $0 or negative values.  If you wish to track discount values, returns, credits or any other revenue that is negative or $0, you must use a custom revenue event to track conversions. 

If you have multiple revenue streams see this article: Set up multiple revenue tracking events

Remove outliers 

Abnormally large orders can substantially affect or misrepresent your average revenue per customer. We recommend filtering out outliers (purchases that far exceed your Average Order Value) from your revenue tracking code, so they don't distort your experiment results.

The Total Revenue Over Time view on the Results page can help you spot outliers. Click view graph in the lower left corner of the metric table.  A new button on the right will appear with a drop down, select 'Total Revenue Over Time'.  This can help you identify when and where outlier events were triggered.  


You'll need to determine what amount is considered an outlier, then modify your code based on that amount. Here's an example using $100 as the threshold (marked here as 10000, because it's the amount in cents):

if(priceInCents < 10000){

  window.optimizely = window.optimizely || [];

     "type": "event",
     "eventName": "trackRevenue",
     "tags": {
       "revenue": valueInCents

If you see an outlier on your Results page, you can remove it by sending an offline conversion to Optimizely.

Check if your revenue event is firing correctly by following the instructions outlined in our Knowledge Base article.