Skip to main content
menu_icon.png

Everything you need to switch from Optimizely Classic to X in one place: See the Optimizely X Web Transition Guide.

x
Optimizely Knowledge Base

Set up revenue tracking in Optimizely X Web

This article is about Optimizely X. If you're using Optimizely Classic, check this article out instead.
 
relevant products:
  • Optimizely X Web Experimentation
  • Optimizely X Web Personalization

THIS ARTICLE WILL HELP YOU:
  • 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.

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:

<script>
   window["optimizely"] = window["optimizely"] || [];

   window["optimizely"].push({
     "type": "event",
     "eventName": "trackRevenue",
     "tags": {
       "revenue": valueInCents
     }
   });
</script>

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.

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.

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.

 
Note:

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.

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!