Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Track events

This topic describes what events are and how they allow you to track the success of your experiment.

Introduction

Experiments allow you to track how users reacted to the different variations. So, you will need to tell Optimizely which events to track in order to gauge the relative success of your experiments. After Optimizely aggregates enough events to produce meaningful metrics, you will be able to judge your experiment variations on the Results page.

As part of your experimental design process, you will choose how to aggregate your tracked events into metrics. Events that power metrics are referred to as conversion events. Conversion events can be big or small. You can implement conversion events to capture clicks, pageviews, form submissions, purchases, scroll depth, etc. In general, you want to track events that are closely associated in terms of user experience with the experimental changes you are making.

Setup overview

At a high level, you will take these steps:

  1. In the Optimizely app, create an event key string and add it to your experiment. See Create events.
  2. Copy the sample integration code for the Track method that Optimizely generates.

📘

Note

We recommend getting in the habit of tracking interesting events even if they are not behind feature flags, so you can more easily create future experiments

  1. Use the Track method to label the event code you want to track. In order for your conversion event to populate metrics on the Results page, you should be tracking the event code that a user is exposed to if:
Now, every time a user triggers the event, Track passes to Optimizely: 
-  **event key**: string that matches the event key you created in the Optimizely app.
-  **user ID**: The user ID must match the ID you passed to the Feature Enabled method.
-  (Recommended ) **userAttributes**  If you set an audience for your experiment, then this is required so that Optimizely can determine if the user who triggered the event is in the experiment audience.  Optimizely also uses this information to give you a visual segmentation of audiences on the Results page.

  1. (Recommended) Filter out third-party bots, so they do not skew your experiment results.

You can track events server-side or client-side using one of the Full Stack SDKs. If you are running Optimizely Agent, you can track events using the track endpoint. You can also track events using the Optimizely Events API for offline events or in places where you cannot implement an Optimizely SDK. For more information, see the Track across platforms section.

🚧

Important

Troubleshooting empty results:

The Results page only shows events that are tracked after Is Feature Enabled has been called for the user who triggered the event. If you do not see results on the Results page, make sure that you are evaluating the feature flag before tracking conversion events.

Example code

The example below shows Track called with all parameters, including optional user attributes.

// Track a conversion event for the provided user with attributes
optimizelyClient.track(eventKey, userId, attributes);
// Track a conversion event for the provided user with attributes
OptimizelyClient.Track(eventKey, userId, attributes);
// Track a conversion event for the provided user with attributes
optimizelyClient.track(eventKey, userId, attributes);
// Track a conversion event for the provided user with attributes
optimizelyClient.track(eventKey, userId, attributes);
// Track a conversion event for the provided user with attributes
optimizelyClient.track("my_conversion", userId, {
  plan_type: "silver"
});
// Track a conversion event for the provided user with attributes
[optimizely track:@"my_conversion"
           userId:@"user123"
       attributes:attributes];
// Track a conversion event for the provided user with attributes
$optimizelyClient->track($eventKey, $userId, $attributes);
# Track a conversion event for the provided user with attributes
optimizely_client.track(event_key, user_id, attributes)
# Track a conversion event for the provided user with attributes
optimizely_client.track(event_key, user_id, attributes)
// Track a conversion event for the provided user with attributes
optimizely?.track("my_conversion", userId:"user123", attributes:attributes)

For more information about when and how to track events, see the other topics in this section.

Track events across platforms

In circumstances where you cannot install the Optimizely SDK (for example, for offline event tracking and other advanced use cases), you can instead use the Event API.

In circumstances where you can install our SDK, you can be sure that all of our SDK languages have the same audience evaluation and targeting behavior, so you will see the same output from sexperiment activation and tracking as long as you are using the same datafile and user IDs. You can use any of our SDKs to track events, so you can run experiments that span multiple applications, services or devices.

For example, if you are running experiments on your server, you can activate experiments with our Python, Java, Ruby, C#, Node or PHP SDKs, but track user actions client-side using our JavaScript, Swift or Android SDKs.

If you plan to use multiple SDKs for the same project, make sure that all SDKs share the same datafile and user IDs.

For more information, see Multiple languages.

Track numeric metrics

It is possible to track nonbinary metrics on the Results page, such as revenue or other numeric values. For information on using reserved event tags to track nonbinary metrics, see Tag events.

Next Steps

After you have created an event:


Next

After you have created an event: