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. When you add the required code to your site (usually on the purchase confirmation page) and add the revenue metric to your experiment, you can 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 your visitors take. However, tracking revenue connects your optimization efforts to the metrics your company values most. 

Things to know

  • 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 must add a small code snippet to your site to call Optimizely Web Experimentation's revenue tracking API. 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 name it what you want. For example, if you want to track the event and name it 'purchases', type 'purchases' in place of 'trackRevenue' in the code block shown above.

ThevalueInCents variable represents the purchase amount, in cents (purchase amount*100). This value must be passed to Optimizely Web Experimentation in cents. Otherwise, your revenue totals will be incorrect. If you do not use US currency, 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 purchase 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 

  • Track revenue after your checkout or billing detail form is successfully submitted to avoid sending revenue totals for invalid purchases to Optimizely Web Experimentation.

  • Avoid triggering the revenue goal at 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.

  • This value must be passed to Optimizely Web Experimentation as an integer. Otherwise, your revenue totals will not be sent to Optimizely Web Experimentation and will not appear 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.

Along with tracking revenue, you can report the purchase event as a conversion by creating a custom event. Add a custom event for 'purchases' (or the value for your 'eventName') on the Results page to track conversions. You do not have to add this event to track revenue.

When you set up multiple custom events to, for example, track different types of revenue, know that the default Overall revenue global metric cumulatively counts 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 adjust it again. The same code can be re-used to track revenue for multiple experiments across the 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 is counted toward the variation total each time Optimizely Web Experimentation receives a revenue amount.

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

  1. Go to Experiments and select or create your experiment.

  2. Click Metrics.
  3. Click Overall Revenue. Overall Revenue becomes your primary metric for this experiment. You can add other metrics as needed and select a different one to be the primary.
    Overall Revenue.png
  4. Choose to measure the Increase or Decrease of revenue for visitors or conversions.
    Revenue metrics.png
  5. Click Save to Experiment.

  6. 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. To track discount values, returns, credits, other negative revenue, or $0, use a custom revenue event to track conversions. 

See Set up multiple revenue tracking events if you have multiple revenue streams.

Outlier smoothing

Abnormally large orders can substantially affect or misrepresent your average revenue per customer. You should keep Enable outlier smoothing checked for revenue metrics so that outliers do not distort your experiment results. See how Optimizely Web Experimentation handles outliers for more information.