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 choose how to turn 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, page views, 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. See How Optimizely Experimentation counts conversions.
Note
You should develop the practice of tracking interesting events, even if they are not behind a flag, so you can create future experiments quickly.
Event properties
Event properties let you attach additional information to an event. For example, you can add information about a product or action performed to create a more specific metric when using the event on the Optimizely Experimentation Results page.
During the beta period, Optimizely Feature Experimentation currently supports event properties as a nested object within event tags. When you call the track event method, you can include event tags as an optional key-value argument. To send event properties, the reserved naming of $opt_event_properties
must be applied when nested into the tags object.
See the links in the Example code section to see how to implement event properties in the track event method. See the Create events documentation for information on setting up event properties. See Create a metric in Optimizely using the metric builder for information on adding event properties to metrics.
Configuration overview
At a high level, you complete the following steps to track events:
- In the Optimizely app or REST API, create an event and a unique key string that you will reference in your code when you call the track event method See Create events.
- Copy the sample integration code for the track event method that Optimizely Feature Experimentation generates in the UI.
- Use the track even method to label the event code you want to track. To ensure your conversion event populates the metrics on the Optimizely Experiment Results page, implement the track event code when users are exposed to a flag variation.
- (Recommended) Filter out third-party bots so they do not skew your experimental results. See Filter out bots.
- Add your events to a flag rule as metrics. See Run A/B tests, Run a multi-armed bandit optimization, and Run flag deliveries.
You can track events on the server and client using one of the Optimizely Feature Experimentation SDKs or Optimizely 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 Experiment Results page only shows tracked events after a
Decide
method is called for the user who triggered the event.If you do not see results on the results page, ensure you are evaluating the feature flag before tracking conversion events.
Example code
The following Swift example shows how you call the track event method, 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 corresponding reference guides.
- Android SDK
- C# SDK
- Flutter SDK
- Go SDK
- Java SDK
- JavaScript (Browser) SDK
- JavaScript (Node) SDK
- PHP SDK
- Python SDK
- React SDK
- React Native SDK
- Ruby SDK
- Swift SDK
For Optimizely Agent, see Use Optimizely Agent.
Track events across platforms
You can track events using the Feature Experimentation SDKs or, for more advanced or offline use cases, use an HTTP-based integration.
If you cannot install an SDK
Use one of the following options:
- Optimizely Event API – Send events directly to Optimizely using a REST API.
- Optimizely Feature Experimentation Agent's tracking endpoint – Forward events through the Agent's
/track
endpoint.
If you can install an SDK
SDKs provide the following benefits:
- Consistent audience targeting – All SDKs evaluate audiences the same way.
- Shared configuration – SDKs use the same datafile and user contexts to ensure consistent experiment decisions and event tracking.
- Cross-platform flexibility – Track events and run experiments across apps, services, or devices using any SDK.
For example, use a server-side SDK (such as Python, Java, or Node) to make experiment decisions and a client-side SDK (such as JavaScript, React, iOS, or Android) to track user behavior.
If you use multiple SDKs within the same project, ensure they share the same datafile and user identifiers. For guidance, see Multiple SDK implementations.
Note
You can also use cross-project events to track events across your Optimizely Web Experimentation and Optimizely Feature Experimentation projects.
Track numeric metrics
On the Experiment Results page, you can track nonbinary metrics 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, complete the following:
- Add events to an experiment flag rule. See Run A/B tests or Run a multi-armed bandit optimization.
- Decide how events are displayed on the Experiment Results page as metrics. See Choose metrics.
More information
For information on how Optimizely Experimentation handles events, see Events: Track clicks, page views, and other visitor actions.
Also, see how Optimizely Experimentation attributes a single user's events over time.
Updated about 16 hours ago