---
title: Track Event for the React Native SDK v4+
slug: feature-experimentation/docs/track-event-for-the-react-native-sdk
docTags: 
createdAt: 2026-08-05T20:39:56.000Z
---

Tracks a conversion event for a user. In other words, tracks an action a user takes. Logs an error message if the specified event key does not match any existing events. See [How Optimizely Experimentation counts conversions](#).

## Minimum SDK version

v4.0.0+

For versions 3.x and earlier, see [React Native SDK prior to v4](docId\:p6sD6Zb_BqayYLvWjLcJB).

## Description

Use the `useOptimizelyUserContext` hook to track conversion events across multiple [flag rules](docId\:zfzSgUawnKhGc59SYlTbL) for a user. You should make only one `trackEvent` call per conversion (user action), even if many rules measure the conversion.

In v4, the `useTrackEvent` hook has been removed. Instead, call `trackEvent` on the user context object returned by `useOptimizelyUserContext`.

:::hint{type="warning"}
The attributes passed when creating the user context (via the `user` prop on `OptimizelyProvider`) are used for [results segmentation](docId:_K6n7h_MZ8b0xn6yWPrrq) on the [Optimizely Experiment Results page](docId\:mrUblIuNVOZc1dvjWdsbw).
:::

## Parameters

- `eventKey` (required) – String – The key of the event to be tracked. This key must match the event key provided when the event was created [in the Optimizely app](docId\:Bf3o37J3IJTUuVR7GshGd) or [REST API](docId\:NxpGs0D4LibV6Jp26feiJ).
- `eventTags` (optional) – Map – A map of key-value pairs specifying the [reserved tag keys](docId\:TPYh_YgbEQNnWIXKthzhl) names and their corresponding values for this particular event occurrence. `eventTags` are contextual metadata about [conversion events](docId\:onBazDzYYz526tL9aQF0s). For example, revenue, load time, or total value. The following are available tag keys:
  - `revenue` – An integer value that is used to track the revenue metric for your experiments, aggregated across all conversion events. `revenue` is recorded in cents.
  - `value` – A floating point value that is used to track a custom value for your experiments. Use this to pass the value for numeric metrics.
  - `$opt_event_properties` –   A map of default and custom event properties and their values.

See [reserved event tags](docId\:TPYh_YgbEQNnWIXKthzhl).

## Returns

This method sends conversion data to Optimizely Feature Experimentation. It does not provide return values.

## Example

```javascript
import { Text, TouchableOpacity } from 'react-native';
import { useOptimizelyUserContext } from '@optimizely/react-sdk';

function CheckoutButton() {
  const { userContext, isLoading, error } = useOptimizelyUserContext();

  const handlePurchase = () => {
    if (userContext) {
      const properties = {
        category: 'shoes',
        color: 'red',
      };

      const tags = {
        $opt_event_properties: properties,
        revenue: 10000,
        value: 100.00,
      };

      userContext.trackEvent('my_purchase_event_key', tags);
    }
  };

  if (isLoading) return <Loading />;
  if (error) return <ErrorDisplay error={error} />;

  return (
    <TouchableOpacity onPress={handlePurchase}>
      <Text>Complete Purchase</Text>
    </TouchableOpacity>
  );
}
```

## Side effects

Additional Feature Experimentation functionality may be triggered by using this method.

### Conversions

Calling this method records a conversion and attributes it to the variations that the user has seen. See [How Optimizely Experimentation counts conversions](docId\:onBazDzYYz526tL9aQF0s).

You can create [metrics](docId\:e2qGf29S6pO8SW90_IVuH) on this conversion event and add metrics to experiments even after the conversion is tracked. See [Events: Tracking clicks, pageviews, and other visitor actions](docId\:puGm9z4XkEG5PDkyaNmlA).

:::hint{type="danger"}
This method does not track events if the event key is invalid.

Changing the traffic allocation of running experiments affects how conversions are recorded and variations attributed to users. See [Why you should not change a running experiment](docId\:IsU8ejnD3mrkAia2mtIOA).
:::

### Notification listeners

Accessing this method triggers a call to the [track notification listener](docId\:PaUUiwg7zYOguMb_HrFGN).

:::hint{type="danger"}
This method does not call the `TRACK` notification listener if the event key is invalid.
:::

## Source files

The language and platform source files containing the implementation for the React Native SDK are available on [GitHub](https://github.com/optimizely/react-sdk).
