This article will help you:
  • Track revenue as a goal in Optimizely to measure the success of your variations
  • Add revenue tracking code to your site

In this article, we explain how to implement revenue tracking on your site using our API.

Optimizely can track revenue from purchases or events on your site, and attribute the amount to a particular experiment and variation. Once you implement the code on your page and add the revenue goal to your experiment, you’ll be able to see the revenue earned per visitor, revenue per paying visitor, purchases, and the total revenue earned per variation on the Results page.

Revenue usually won't be your primary goal because it's not a direct action that your visitor takes, but it's a great way to tie your optimization efforts to the metrics that your company values most.

To see the implementation in action, check out our short video on custom event goals and revenue tracking:


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.

Implement the Optimizely revenue tracking code

To track revenue, you’ll need to add a small snippet of code to your site, usually on the purchase confirmation page. The required custom event that calls our revenue tracking API is:

   window.optimizely = window.optimizely || [];
   window.optimizely.push(['trackEvent', 'eventName', {'revenue': valueInCents}]);
  • 'eventName' - This parameter is required, and you may choose the value that goes there. If, for example, you wanted to track the event and name it ‘purchases’, you would put ‘purchases’ in place of ‘eventName’.

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

  • valueInCents - This is the numerical representation of the purchase amount in cents (purchase amount*100). It is crucial that you pass this value to Optimizely in cents, otherwise your revenue totals will be incorrect.

    If you do not use U.S. currency (cents), simply multiply the purchase amount in your currency by 100. For example, a purchase amount of 54.99 should be passed as 5499.

  • The rest of the code will stay the same.

Once you have this code implemented on your page, you will not need to make adjustments to it again. The same code can be used to track revenue for multiple experiments.

Add the Revenue Goal to an Experiment

  1. To add a revenue goal to your experiment, click the Goals icon () in the Editor, then Add a Saved Goal.

  2. In the Saved Goals list, click Total Revenue. If you are using an older Optimizely project, you may see this goal labeled as Revenue instead of Total Revenue. There is no difference in functionality.

When the Revenue Custom Event is triggered, the revenue amount will be attributed to every experiment variation that is active for the current visitor. So, if a visitor passed through three experiments and made a purchase, the revenue amount would show up in all three experiments.

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.

Segment Your Revenue by Product

Unlike most other goals, the revenue goal is cumulative and is not de-duplicated based on the visitor’s unique user ID. As such, revenue will be counted toward the variation total each time the visitor makes a purchase.

If you want to track revenue for a specific product (to see, for example, how a variation affected a specific product's revenue), follow these instructions.


Please keep in mind that this solution requires Custom Dimensions, an Enterprise Plan feature.

  1. Create a new custom dimension in Optimizely.
  2. Create your revenue goal as usual, but change the code to include an API call adding visitors to the new dimension that you created:
    // This is the unique identifier of the product. It can be any value you want. For example, if the dimension name is “shirts”, one value might “long-sleeved”.
    var value = ‘youDefineThisValue’;
    // Revenue must be added in cents
    var valueInCents = 20000;
    window['optimizely'] = window['optimizely'] || [];
    window['optimizely'].push(['setDimensionValue', dimensionId/Name, value]);
    window['optimizely'].push(["trackEvent", "eventName", {"revenue": valueInCents}]);
  3. Modify the above example to reflect the actual product, price, and the API call that you generated from the Custom Dimensions menu. This code will add the visitor to a custom dimension, and the revenue will be associated with that custom dimension on the results page.


If you see duplicated orders on your Results page, you can remove them manually by sending an offline conversion to Optimizely. Learn more about that solution in our revenue goals troubleshooting article.

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 revenue distribution view on the Results page can help you spot outliers. Click Distribution in the revenue distribution chart to view the share of conversions by revenue amount.

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 || [];

'orderComplete', {'revenue': priceInCents}]);


If you see an outlier on your Results page, you can remove it by sending an offline conversion to Optimizely. Learn more about that solution in our revenue goals troubleshooting article

Other Resources

  • Looking for other types of goals to track? Check out our goals overview!
  • Trying to troubleshoot a revenue goal? Check out our troubleshooting goals article!
  • Looking for the definitive guide to getting up and running with Optimizely? Learn and practice your Optimizely skills and web optimization strategy in Optimizely Academy.
  • Have a question about revenue tracking with Optimizely? Head over to the Optimizely Community to post a discussion and see what others are talking about.
  • Trying to set up a revenue tracking goal for a mobile experiment? Check out our developer documentation for a step-by-step walk-through.