The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideAPI Reference
Dev guideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Track user events

Explains events in Optimizely Feature Experimentation, which let you to track the success of your experiments.

Experiments let you track how users reacted to the different variations. So, you must tell Optimizely Feature Experimentation which events to track to gauge the relative success of your experiment. After Optimizely Feature Experimentation aggregates enough events to produce meaningful metrics, you can judge your flag variations on the Optimizely Experiment Results page.

You will choose how to aggregate your tracked events into metrics as part of your experimental design process. User 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, and so on. In general, you want to track events closely associated with the user experience your experiments are updating.

Setup overview

At a high level, you will take these steps:

  1. In the Optimizely app, create an event and a unique key string that you will reference in your code when you call Track Event. See Create events.
  2. Copy the sample integration code for the Track Event method that Optimizely Feature Experimentation generates.
  3. Use the Track Event method to label the event code you want to track. For your conversion event to populate experiment metrics on the Experiment Results page, Track Event code that a user is exposed to if they see a flag variation.

πŸ“˜

Note

You should get in the habit of tracking interesting events, even if they are not behind a flag, so you can more easily create future experiments.

  1. (Recommended) Filter out third-party bots so they do not skew your experimental results. For information, see Filter out bots.
  2. Add your events to a flag rule. See Run A/B tests and Run flag deliveries.

You can track events server and client-side using one of the Optimizely Feature Experimentation SDKs or Agent. You can also track events using the Events API, where you do not have an Optimizely Feature Experimentation SDK implemented. For information, see Track across platforms.

🚧

Important

The Experiemnt Results page only shows events that are tracked after a Decide method 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 the Track Event method called, including optional user attributes.

// Track a conversion event for the provided user with attributes
let user = optimizely.createUserContext(userId: "user123", attributes: ["logged_in":true])
  
// Track a user event
try? user.trackEvent(eventKey: "purchased")

For the other SDKs, refer to the reference guide:

For Optimizely Agent, see Use Optimizely Agnet.

Track events across platforms

In circumstances where you cannot install a Feature Experimentation 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 a Feature Experimentation SDK, you can rest assured that all of the SDK languages have the same audience evaluation and targeting behavior, so you see the same output from experiment decisions and tracking as long as you are using the same datafile and user contexts. You can use any of the SDKs to track events, so you can run experiments that span multiple applications, services, or devices.

You can also use cross-project events to track events across your Optimizely Web Experimentation and Optimizely Feature Experimentation projects.

For example, you can make the experiment decisions using a server-side SDK (Python, Java, Ruby, C#, Node, or PHP SDKs) but track user actions using a client-side SDK (including JavaScript, React, iOS, or Android SDKs).

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

For information, see Multiple SDK implementations.

Track numeric metrics

You can track nonbinary metrics on the Experiment 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 Create events: