---
title: Track user events
slug: feature-experimentation/docs/track-events
docTags: 
createdAt: 2026-08-05T20:39:53.000Z
---

Experiments let you track how users react to different variations. To measure the relative success of your experiment, you must tell Optimizely which [events](docId\:puGm9z4XkEG5PDkyaNmlA) to track. After Optimizely aggregates enough events to produce meaningful metrics, you can evaluate your flag variations on the [Experiment Results page](docId\:mrUblIuNVOZc1dvjWdsbw).

As part of designing your experiment, you decide which tracked events to use as metrics. Events that track a desired user action, like a purchase, signup, or form submission, are called conversion events. They can capture anything from simple clicks and page views to purchases and scroll depth. In general, you want to track events closely associated with the user experience your experiments are updating. See [How Optimizely counts conversions](docId\:onBazDzYYz526tL9aQF0s).

:::hint{type="info"}
**Note**
You should develop the practice of tracking interesting events, even if they are not behind a flag, so you can create future experiments.
:::

## 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 on the Experiment Results page.

Optimizely supports event properties as a nested object within [event tags](docId\:E4kGQiwGcruXWHm-1n_HW). When you call the track event method, you can include event tags as an optional key-value argument. To send event properties, use the reserved key `$opt_event_properties` as a nested key within the tags object.

Go to [Example code](docId:7z1ZuPEvPJJkghG28HRv9) for implementation examples, [Create events](docId\:v2goO-UxyIA4AtTSR-h-9) for configuration instructions, and [Create a metric using the metric builder](docId\:cphstZe3xKhsY7WsnnLZK) for guidance on adding event properties to metrics.

## Configuration overview

:::hint{type="warning"}
**Important**
The [Experiment Results page](docId:_K6n7h_MZ8b0xn6yWPrrq) 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 Experiment Results page, ensure you are evaluating the feature flag before tracking conversion events.
:::

At a high level, complete the following steps to track events:

1. In the Optimizely app or REST API, create an event with a unique key string that you will reference in your code when you call the track event method. See [Create events](docId\:v2goO-UxyIA4AtTSR-h-9).
2. Copy the sample integration code for the track event method that the UI generates.
3. Call the track event method to record the event you want to track. To ensure your conversion event populates the metrics on the [Experiment Results page](docId:_K6n7h_MZ8b0xn6yWPrrq), call the track event method after users are exposed to a flag variation, that is, after you evaluate the flag for that user.
4. (Recommended) Filter out third-party bots so they do not skew your experimental results. See [Filter out bots](docId\:XgllFIgMAg9q1veDvoFQ9).
5. Add your events to a flag rule as metrics. See [Run A/B tests](docId:8pnfCv-sR37goLcxTtCPv), [Run a multi-armed bandit optimization](docId:9Tu731hmFrs5KHzlIsT7N), and [Run flag deliveries](docId:_BjMxuGwwlVrhkNcx2kzm).

You can track events on the server and client using an SDK or the Agent. You can also track events using the [Events API](docId:822ZQOB6Zk2-kWJKavBvA) if you do not have an SDK implemented. For information, see [Track across platforms](docId:3kGIZlCkODJIOJuT3bdWo).

## Example code

The following Swift example shows how to call the track event method, including optional user attributes.

```swift
// 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](docId\:kRTOAg7BcKHnsSYIOGsT8)
- [C# SDK](docId\:t2cdt_4CYXEkRKj2R_Qx9)
- [Flutter SDK](docId:0X4lEtIQOTNKuCjk9kNmn)
- [Go SDK](docId\:LcdvFIfZ7GfSxd1M1qb_N)
- [Java SDK](docId\:siDJxMQqZQdP3-_90yI3o)
- [JavaScript SDK](docId\:m3uU-JFwOjZgWUBjhQfn2) – SDK versions 6.0.0 and later.
- [JavaScript (Browser) SDK](docId\:dtQJ11RFUGmfz559B_i18) – SDK versions 5.3.5 and earlier.
- [JavaScript (Node) SDK](docId\:QAxkszUJv8lJBPAtkhTH2) – SDK versions 5.3.5 and earlier.
- [PHP SDK](docId\:kVuqN1eWmfu_JGnMnXarJ)
- [Python SDK](docId:_Z3MmQTkwUR-QgKN8kuMf)
- [React SDK](docId\:t8DEKX6FHRjIR4UiXr0Yh)
- [React Native SDK](docId:0yISQpKrQP3cySgKUzHy7)
- [Ruby SDK](docId\:e0Bu1wqkxwIdIw4inzSIC)
- [Swift SDK](docId\:I9jAN0zACRv-CVA3e-jS2)

For Optimizely Agent, see [Use Optimizely Agent](docId\:uhGRMsjV6oSlDxKZO_kn5).

## Track events across platforms

You can track events using the SDKs or, for more advanced or offline use cases, an HTTP-based integration.

### If you cannot install an SDK

Use one of the following options:

- [Optimizely Event API](docId\:Hq6lC7WxnHplkT15hOzXN) – Send events directly to Optimizely using a REST API.
- [Optimizely Agent](docId\:uhGRMsjV6oSlDxKZO_kn5) – 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](docId\:qnt_DGgMVhpq-GXr3gqje).

:::hint{type="info"}
**Note**
You can also use [cross-project events](docId\:ZL_1cekoRgYONCLUBrv5b) to track events across your Web Experimentation and 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](docId\:TPYh_YgbEQNnWIXKthzhl).

## Next steps

After you [Create events](docId\:v2goO-UxyIA4AtTSR-h-9), complete the following:

- Add events to an experiment flag rule. See [Run A/B tests](docId:8pnfCv-sR37goLcxTtCPv) or [Run a multi-armed bandit optimization](docId:9Tu731hmFrs5KHzlIsT7N).
- Choose how events are displayed on the Experiment Results page as metrics. See [Choose metrics](docId\:e2qGf29S6pO8SW90_IVuH).

## More information

For information on how Optimizely handles events, see [Events: Track clicks, page views, and other visitor actions](docId\:puGm9z4XkEG5PDkyaNmlA).

Also, see [how Optimizely attributes a single user's events over time](docId:_sy-mNT1TCvYW-EA2m_Ls).
