Skip to main content


Optimizely Knowledge Base

Metrics and events in OpX

Events are the "verbs" of Optimizely experiments. They're how you track actions associated with the subjects of your experiment. Events are reusable, so you can quickly add them to any experiment you build. After you add an event to an experiment, it is called a metric.

Events are not shared or reusable between multiple projects. This means you will set up, track, and manage events within the context of a single project.

Events do not track data until you’ve configured and activated them. If you add an event as a metric to an experiment that was previously running, the data for that event will be added retroactively, from the date the event was created or the date the experiment was published, whichever is more recent. 

Events can be associated with any action your team can track in Salesforce. To make a new event, first create an event record within the Optimizely app, then configure an event using Process Builder or Apex Code.

Create event records

To create a new event record, follow these steps:

  1. Click the dropdown caret next to the Events tab and click + New Event.

  1. Fill out the required fields (marked with a red asterisk *). 

  2. When you’re finished, click Save

Optimizely automatically generates a unique event ID and event key when you save a new event; for this reason, we do not recommend manually entering information into these fields.

Additionally, the Event Type field must remain the default value, Custom

Below is an example of a completed event record. You will use the event ID and event key to connect this record with the event you configure in the next step.

Configure events

You can configure events using Process Builder or using custom Apex Code. Learn more about setting up events in the Data and Attribution app configuration guide.

Configure Events in Process Builder

If you’re using Process Builder, the first step is defining criteria and conditions for an action group. You will then configure the Process Builder’s immediate action. Select Create a Record as the action type. This will ensure you can set the record type as Conversion Event.

Next, populate the Event ID and Event Key fields. To do this, select the corresponding event ID and event key from the event record you created.

Configure Events Using Apex

In order to communicate a conversion event without using Process Builder, you will need to fire the platform event from a given Component, and ensure that the Event ID, Event Key, and VisitorID attributes are part of the fired platform event. Below is an example.

optimizely_dna__Conversion_Event__e conversionEvent = new optimizely_dna__Conversion_Event__e)
conversionEvent.optimizely_dna__Event_Id__c = 'REPLACE';
conversionEvent.optimizely_dna__Event_Key__c = 'REPLACE';
conversionEvent.optimizely_dna__Visitor_Id__c = 'REPLACE';

One thing to keep in mind is how Optimizely does attribution of conversion events for a results page. The visitor ID you send with a conversion event also needs to have been "bucketed" into an experiment via a decision event prior to the conversion. Otherwise, the results page won't attribute the conversion event for that visitor to the experiment. Here's some additional documentation on our attribution model.

Manage events

Optionally, you can archive an event. Any existing metrics associated with that archived event will continue to work, but as noted, you cannot create new Metrics using it.

Create a metric

To start any experiment, you’ll need to define a metric. Metrics help you measure differences in behavior based on changes you make using a variation. Metrics can only be created from active events, so if you haven’t created the appropriate event yet, do that first.

Before creating a new metric:

  • Update the experiment status to Paused if the experiment is running or archived. 

  • Make sure the event you want to associate with the metric is active (events are active by default when they’re created).

To create a new metric record, follow these steps:

  1. Open the experiment the metric will be associated with, then click the New button in the metrics list. Alternatively, you can open an event record and click the New button within that record.

  1. Fill in the required fields (they’re marked with a red asterisk *). If this metric was created from within the experiment record, the Experiment field will be automatically populated with the correct ID and should not be modified. If you created this metric from within the event record, you’ll need to select an experiment for the metric.

Every metric requires a winning direction, aggregator, scope, and event. Take, for example, this statement:

“Increase in conversions (unique) per visitor for Case Resolved in Under 1 Day”

It contains all four of a metric’s required components:

  • Winning Direction

    • The winning direction tells Optimizely what kind of change you hope to see: an increase in your metric, or a decrease. In most experiments and campaigns, you will want to see your metrics increase. However, for some metrics — like time required to resolve a customer issue — a lower value (i.e., negative lift) would be more desirable.
      Select Increasing or Decreasing from this dropdown.

  • Aggregator

    • The aggregator acts as the numerator of your metric. Select Unique when you are interested in the number of visitors, sessions, or events with at least one conversion. Select Count when you want to know about the total number of visitors, sessions, or events.

  • Scope:

    • Where the aggregator is the metric’s numerator, the scope acts as your metric’s denominator. Think of this as the rate at which your metric measures its numerator. For example, you may measure unique conversions per visitor.
      For Salesforce Experiments, it must be set to Visitor

  • Event

    • The event is the whole reason you’re doing the experiment in the first place. Maybe you’re interested in tracking conversions. Or perhaps site visits. Or support cases resolved in less than a day. Without an event, your metric has no trigger, nothing to tell it something worth measuring has happened.

You’ll also need to decide if your metric will be the primary metric for the experiment. Experiments can have multiple metrics, but Optimizely sometimes needs to know which one you consider most important. Each experiment must have one and only one primary metric.

Changing the primary metric after an experiment has begun is not recommended.

  1. When you’re done, click Save.

Below is an example of a completed metric record.

You can delete metrics, but you cannot archive them.