Set up revenue tracking in Optimizely Web Experimentation

  • Updated
  • Optimizely Web Experimentation

Optimizely Web Experimentation 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 will be able to see the revenue earned per visitor, revenue per paying visitor, purchases, and the total revenue earned per variation on your Results page.

Revenue should not 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 Web Experimentation, 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 Web Experimentation snippet must be present on the page where you are tracking revenue.
  • The valueInCents variable is tracked in cents, so $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 valueInCentsvariable.

Implement the Optimizely Web Experimentation revenue tracking code

To track revenue, you will need to add a small snippet of code to your site to call Optimizely Web Experimentation'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.

ThevalueInCents variable represents the purchase amount, in cents (purchase amount*100). It is crucial that this value is passed to Optimizely Web Experimentation 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;

You can choose which currency symbol is displayed for revenue metrics on the Optimizely Web Experimentation Results Page.

Best practices 

  • It is 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 Web Experimentation.

  • 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 Web Experimentation on each click.

  • It is also crucial that this value is passed to Optimizely Web Experimentation as an integer. Otherwise, your revenue totals will not be sent to Optimizely Web Experimentation 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. You do not have to add this event in order to track revenue.

When you set up multiple custom events to, for example, track different types of revenue, be mindful of 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 or which project or Optimizely Experimentation product (Web Experimentation or Feature Experimentation) the event tracking is instrumented.

When you implement this code on your page, you do not 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 Web Experimentation receives a revenue amount.

To more accurately count how many transactions have been received by Optimizely Web Experimentation, 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

Add the Overall Revenue metric to your experiment to let Optimizely Web Experimentation know that you want to track revenue for this experiment. 

overall-revenue-example.gif

  1. Open the experiment.

  2. Under Manage Experiment, click Metrics.

  3. The Metrics panel opens. Click the custom event labeled Overall Revenue 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 is not the ideal choice for a primary metric).

  4. Click Save to Experiment.

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

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 Set up multiple revenue tracking events.

Outlier smoothing

Abnormally large orders can substantially affect or misrepresent your average revenue per customer. We recommend enabling outlier smoothing, for revenue metrics so that outliers do not distort your experiment results. To find out more and to enable outlier smoothing in A/B experiments, please read our article on how Optimizely Web Experimentation handles outliers.