---
title: Optimizely X Tracking Module
description: Provides an integration between Optimizely X and Tealium Collect. The module listens for events triggered by the OptimizelyX library and passes the event data to Tealium Collect.
url: https://docs.tealium.com/platforms/android-java/module-list/optimizely-x-tracking/
---
## Requirements

* [Optimizely X Android SDK](https://developers.optimizely.com/classic/android/getting-started/index.html) added to your app


## Install

Install the Optimizely X Tracking module with Maven or manually.

### Maven

To install the Optimizely X Tracking module with Maven:

1. In your project's top-level `build.gradle` file, add the following Maven repository:
      ```groovy
      maven {
            url "https://maven.tealiumiq.com/android/releases/"
      }
      ```

2. In your project module's `build.gradle` file, add the following Maven dependency:
      ```groovy
      dependencies{
            //only required if you do not have this reference
            implementation 'com.tealium:library:5.8.0'
            implementation 'com.tealium:optimizelylistener:1.1.2'
            //only required if you do not already have this reference and require lifecycle tracking
            implementation 'com.tealium:lifecycle:1.1.4'
      }
      ```

### Manual

To install the Optimizely X module manually:

1. Download the Tealium [OptimizelyListener](https://github.com/Tealium/tealium-android/tree/master/Modules/Optimizely) module.

2. In your top-level `build.gradle` file, verify the following:  
      ```groovy
      allprojects {
            repositories {
            mavenCentral()
            flatDir {
                  dirs 'libs'
            }
            }
      }
      ```

3. Copy the file `tealium.optimizelylistener-1.1.1.aar` into your project's `<PROJECT_ROOT>/<MODULE>/libs` directory.

4. Add the Tealium library dependency to your project module’s `build.gradle` file:
      ```groovy
      dependencies {
            // only required if you do not already have this reference
            implementation(name:'tealium-5.6.1', ext:'aar')
            implementation(name:'tealium.optimizelylistener-1.1.1', ext:'aar')
            // only required if you do not already have this reference and require lifecycle tracking
            implementation(name:'tealium.lifecycle-1.1.2', ext:'aar')
      }
      ```

## Initialize

The module must be initialized after the `OptimizelyManager` has finished initializing. If initialized elsewhere, some or all events may not be tracked.

`Optimizely` provides a listener which is called as soon as the `OptimizelyManager` is initialized.

```java
// import the Tealium OptimizelyListener module in the import section
import com.tealium.optimizelylistener.TealiumOptimizelyEventListener;
//...

// substitute the example instance name here with the same instance name you used when initializing the Tealium library
private static final String TEALIUM_INSTANCENAME = "teal";

myOptlyManager.initialize(getApplicationContext(), new OptimizelyStartListener() {
    @Override public void onStart(OptimizelyClient optimizely) {
        // call this to init the Optimizely listener with a valid OptimizelyManager instance
        // myOptlyManager is your own reference to the global OptimizelyManager instance
        TealiumOptimizelyEventListener.init(TEALIUM_INSTANCENAME, myOptlyManager);
        // activate experiment AFTER initializing the Tealium listener.
        // tracking calls are missed if not done in this order.
        Variation v = optimizely.activate("tealiumtest", "userid");
    }
});
```

Once you have initialized the module, no additional configuration is required. The module listens for notifications from the `Optimizely` SDK and pass the data to the Tealium SDK as required.


## Auto-Tracked Events

There are two types of `Optimizely` events are passed along to Tealium Collect: experiments and custom events. 

These events are set in the `tealium_event` variable with the values:

* **Optimizely Experiment Started**  
When the `Optimizely` SDK activates an experiment.
* **Optimizely Event Tracked**  
When the `Optimizely` SDK receives a custom event (generated by manually calling `Optimizely`'s `track` method).

## Data Layer

The following event attributes are included in the tracked `Optimizely` events:

| Variable | Scope | Description | Example |
| --- | --- | --- | --- |
| `optimizely_ experiment_key` | Volatile (session) | `Optimizely` experiment name | `"Homescreen MVT"` |
| `optimizely_ variation_key` | Volatile (session) |  `Optimizely` variation name | `"Variation A"` |
| `optimizely_ user_id` | Volatile (session) | `Optimizely` user ID | `"[alice@tealium.com](mailto:alice@tealium.com)"` |
| `optimizely_ event _key` | Hit (single event) | `Optimizely` event name | `"purchase"` |
| `optimizely_ event _value` | Hit (single event) | `Optimizely` event value | `"123"` (integers only) |
| `optimizely_ XXX` | Hit (single event) | All `Optimizely` custom attributes are prefixed with `"optimizely_"` and passed directly to Tealium | |

### Variable Name Overrides (Optional)

The default variable names are overridden easily if you prefer a different naming convention. Overriding variable names is done by changing a set of public properties on the `TealiumOptimizelyEventListener` class.

```java
import com.tealium.optimizelylistener;
//...

TealiumOptimizelyEventListener.OPTIMIZELY_EXPERIMENT_KEYNAME = <your new value>;
TealiumOptimizelyEventListener.OPTIMIZELY_VARIATION_KEYNAME = <your new value>;
TealiumOptimizelyEventListener.OPTIMIZELY_USERID_KEYNAME = <your new value>;
TealiumOptimizelyEventListener.OPTIMIZELY_EVENTKEY_KEYNAME = <your new value>;
TealiumOptimizelyEventListener.OPTIMIZELY_EVENTVALUE_KEYNAME = <your new value>;
TealiumOptimizelyEventListener.OPTIMIZELY_EXPERIMENT_STARTED = <your new value>;
TealiumOptimizelyEventListener.OPTIMIZELY_EVENT_TRACKED = <your new value>;
TealiumOptimizelyEventListener.OPTIMIZELY_ATTRIBUTE_PREFIX = <your new value>;
```

## API Reference

For the complete reference of methods for the Optimizely X Tracking Module, see the [`TealiumOptimizelyEventListener`](https://tealium.github.io/tealium-android/com/tealium/optimizelylistener/TealiumOptimizelyEventListener.html) class in the Tealium SDK for Android API.
