Set up multiple revenue tracking events

  • Updated
  • Optimizely Web Experimentation
  • Optimizely Performance Edge

If you have multiple products or checkout funnels you wish to track independently, Optimizely Web Experimentation and Optimizely Performance Edge have that flexibility by adding the revenue tag to any custom event. This article builds on the instructions to implement the revenue tracking event outlined in Set up revenue tracking in Optimizely Web Experimentation and assumes you have read the article.

Depending on the funnels of your site, and the revenue values you wish to track independently, you must take extra care in deciding if the overall revenue metric will work for you.

Before you set up multiple revenue-tracking events, read through this entire article, especially if you have already set up revenue tracking on your site. Multiple revenue tracking events can skew the overall revenue metric if set up incorrectly. The cumulative sum of all values passed in the revenue tag regardless of the event name and which project or product the event tracking is instrumented. 

Overall revenue and custom revenue tracking events

Out of the box, Optimizely gives all projects overall revenue as a metric that you can add to any experiment. Overall revenue is not an event. No conversion in the Experimentation Events Export data has the name overall revenue. There is no event API name or ID. Instead, overall revenue is a special calculation Optimizely does on the results page based on events generated by visitors bucketed in the experiment.

To generate overall revenue, Optimizely looks for events that meet the following two conditions:

  1. Events that have a revenue tag.
  2. A revenue tag with a value greater than $0.

Regardless of the event name, overall revenue will count as a conversion towards the overall revenue metric if an event meets the above criteria.

On the other hand, custom revenue tracking events are actual events sent to Optimizely Experimentation using the Event API. Optimizely records these events as conversions, calculated on the results page as a stand-alone metric. The number of conversions for a custom revenue tracking event is specific to that custom metric. The value of revenue calculated is the sum of the revenue tag values associated with the custom event with that name only.

Overall revenue does not count as $0 or negative values. If you want 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.

Decide when to use overall revenue

Depending on the funnels of your site, and the revenue values you want to track independently, you must take extra care in deciding if overall revenue will work for you. If you choose to track multiple revenue streams on your site, you must create a custom event that tracks every revenue stream on your site independently or create custom events to track revenue to take the place of the overall revenue metric.

Because overall revenue is a sum of events with a revenue tag, it is important to ensure that the values that can be consumed by overall revenue are accurate. If you have set up a revenue tracking event as outlined in the Set up revenue tracking, then an event totalRevenue is placed on your confirmation page, capturing all revenue. Overall revenue is, in turn calculating all revenue on your site by reading the totalRevenue event's revenue tag. Adding additional revenue events that track one product line within the funnel can cause overall revenue to become inflated if those products are already tracked in the totalRevenue event. Thus you must make an adjustment to your configuration.

Keep using the overall revenue metric

To keep the overall revenue metric, remove any revenue events that capture all revenue transactions. Then create a new event for each product line or revenue stream that comes through your checkout. When a visitor checks out, you should capture all products in the cart by only one revenue event. Ensure that no product or dollar amount is unaccounted for, as this will cause revenue to be missed.

You cannot remove overall revenue from the project, so it may be helpful to continue using this metric to prevent confusion.

Replace overall revenue with totalRevenue

If there are too many products to create custom events for, or you cannot accomplish the complexity of capturing each item in the funnel, then you can use a custom event that collects all revenue in place of the overall revenue metric.

For this approach, there are two parts; the first is to set up an event that tracks all revenue, regardless of the product purchased. If you set up totalRevenue as outlined in the Set up revenue tracking article, then you can use this metric. Just ensure that you add the custom event to your project.

The second step is to set up logic that evaluates the revenue for just the products you wish to track independently. You should then convert the revenue to cents and store it as a unique variable. Create a custom event that is designated to track just that product, and pass the custom variable as the value to the revenue tag.

You can add this event to the same page as the totalRevenue event. When a visitor checks out and has purchased the special item along with other items, then both events will be fired off at the same time.

Example: Track multiple streams of revenue

If you want to track multiple types of revenue on your site, you can do so by creating custom events that include the revenue tag. Adding the revenue tag does two things:

  • Allows a value to be passed to Optimizely Experimentation.
  • It marks the event to be tracked by overall revenue.  
Overall revenue sums all values passed in the revenue tag regardless of the event name and which project or experimentation product the event tracking is instrumented in.

An example of this use case is if your site has multiple revenue funnels or multiple products you want to track individually. Assume you have an ecommerce site that sells two types of products: widgets and wingdings. This store wants to track all the revenue on the site but also wants to track the revenue for each product separately. To do this, create a custom revenue event for widgets and a second custom event for wingdings. Because these are the only two products on this ecommerce site, by tracking the revenue for both these products, all revenue through the funnel is covered, and the overall revenue metric is used.

This example starts with creating a custom event for the first product, widgets:

Example: Create a custom event for each revenue stream

  1. Go to Implementation > Events.
  2. Click Create New Event.
  3. Select Custom
  4. Enter the Name and API Name that is distinct for the type of revenue event you want to track. The API name automatically populates in the API Call field.
  5. Copy the generated code from the API Call field and place the code onto the confirmation page of the checkout funnel. This ensures the transaction was successful before sending the event.
  6. Click Save Event.
  7. Repeat steps 1 through 6 for each type of revenue event you wish to track.

If you are working with the scenario outlined above, you should create two custom events, one custom event to track each of the two products: widgets and wingdings.  

If you have more products that are not covered by the metrics tracked independently, use the steps above to create an all revenue event. If you choose to track all revenue through a custom event, do not use overall revenue. Overall revenue will count the individual product events, as well as the all revenue event, which will cause overall revenue to appear inflated.

3RevenueEvents.png

Example: Create custom logic to isolate the revenue streams

Next, create custom logic that will pass the value for each revenue stream into a variable that can be passed to Optimizely Experimentation using the custom event API. Each revenue stream needs its own independent variable that is associated with a specific revenue custom event. Ensure that the value passed is converted into a single currency denomination and converted to cents before the value is passed to the revenue tag of the custom event.

Optimizely recommends that you place the revenue tracking events on the confirmation page after a successful transaction has occurred. You can add multiple revenue events to the same page as long as the variable used to pass the transaction amount to the revenue tag is evaluated independently for each event.

For the example of two revenue events, the confirmation page logic may look something like the following:

//pass the total purchase amount of just widgets
var valueOfWidgets = ‘youDefineThisWidgetsValue’;

//pass the total purchase amount of just wingdings
var valueOfWingdings = ‘youDefineThisWingdingsValue’;

// Convert all revenue into cents
var widgetsInCents = valueOfWidgets * 100;
var wingdingsInCents = valueOfWingdings *100;

   window["optimizely"] = window["optimizely"] || [];
     window["optimizely"].push({
     "type": "event",
     "eventName": "trackWidgetRevenue",
     "tags": {
       "revenue": widgetsInCents
     }
    });
    
    window["optimizely"].push({
     "type": "event",
     "eventName": "trackWingdingRevenue",
     "tags": {
       "revenue": wingdingsInCents
     }
   });

If you decide not to use the overall revenue metric and instead want to set up your own custom event, then create an additional goal that captures all revenue in addition to each revenue stream. The code for this on the confirmation page will look something like the following:

//pass the total purchase amount to a variable
var value = ‘youDefineThisTotalValue’;

//pass the total purchase amount of just widgets
var valueOfWidgets = ‘youDefineThisWidgetsValue’;

//pass the total purchase amount of just wingdings
var valueOfWingdings = ‘youDefineThisWingdingsValue’;

// Convert all revenue into cents
var valueInCents = value * 100;
var widgetsInCents = valueOfWidgets * 100;
var wingdingsInCents = valueOfWingdings *100;

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

   window["optimizely"].push({
     "type": "event",
     "eventName": "trackRevenue",
     "tags": {
       "revenue": valueInCents
     }
   });
   window["optimizely"].push({
     "type": "event",
     "eventName": "trackWidgetRevenue",
     "tags": {
       "revenue": widgetsInCents
     }
   });
   window["optimizely"].push({
     "type": "event",
     "eventName": "trackWingdingRevenue",
     "tags": {
       "revenue": wingdingsInCents
     }
   });

Finally, add the custom events to your experiment to track conversions for each revenue stream.

Pick the right revenue metric for your experiment

With the metric builder, you can decide the best way to break down data on the results page using different combinations of the revenue events you have created. To demonstrate this, the following sections use the widgets and wingdings example from above.

Revenue metrics by total visitors

If you are running an experiment that calls attention to your new wingding product, where the goal is to increase the number of visitors that purchase a wingding product, then conversions by the visitor is a good approach. To set this up:

  1. Go to the Experiments page and click the name of your experiment (in this example, Widgets and Wingdings).
  2. Click Metrics.
  3. Expand Custom Events and select Wingdings-Only Revenue.
  4. Select Increase from the first drop-down list (because increasing revenue is considered a win).
  5. Select total revenue from the second drop-down list. This changes how Optimizely calculates the event. Instead of, by default, counting one conversion per instance of the event, Optimizely looks at the value passed with the revenue tag, takes a sum of those values, and displays the result in the form of currency.
  6. Select visitor from the third drop-down list. This becomes the denominator for the metric.
  7. Click Save to Experiment, then click Save.
  8. When you run the experiment, and you will see revenue come in per visitor.

Revenue metrics by total conversions

If you have an experiment where you want to encourage visitors to buy more than one widget in a transaction, it is better to look at the number of conversions as a denominator. This approach measures if the amount spent increased for the visitors that made a purchase.

To do this, follow the same steps from the Revenue metrics by total visitors section, except for step 6, select conversions as the denominator:

  1. Go to the Experiments page and click the name of your experiment (in this example, Widgets and Wingdings).
  2. Click Metrics.
  3. Expand Custom Events and select Wingdings-Only Revenue.
  4. Select Increase from the first drop-down list (because increasing revenue is considered a win).
  5. Select total revenue from the second drop-down list. This changes how Optimizely calculates the event. Instead of, by default, counting one conversion per instance of the event, Optimizely looks at the value passed with the revenue tag, takes a sum of those values, and displays the result in the form of currency.
  6. Select conversions from the third drop-down list. This becomes the denominator for the metric.
  7. Click Save to Experiment, then click Save.
  8. When you run the experiment, you will see revenue come in per conversion.

Comparing the results for the wingding revenue examples above, notice that the dollar amount is the same, but the data given is much different. In the revenue per visitor example, you are closer to statistical significance, and the total improvement is much greater.

By changing the denominator from total visitors to the total population that converted to the event (total conversions), the population drops considerably. Notice that there is a much smaller improvement rate even though the revenue per conversion is substantially more. By removing all the visitors that spent $0, you can evaluate the difference in the totals of those who made purchases. As a result, the statistical significance takes more time and more visitors when looking at metrics by conversion instead of by visitor.

Revenue metrics as a custom event

If you do not have a static confirmation page, but you still want to evaluate how many times the custom revenue event was triggered, simply add the wingding metric to the results page. But instead of changing the event type to total revenue, use total conversions.

This will give you a numeric value of how many times the revenue event was triggered.