Optimizely X Tracking Module for Android

Optimizely X Tracking Module for Android

by on ‎08-15-2017 05:50 AM - edited a month ago by Community Manager (78 Views)

The Optimizely Tracker module for the Tealium iOS library is an integration between Optimizely X and Tealium Collect. The module listens for events triggered by Optimizely X library and passes the event data to Tealium Collect.

Table of Contents Placeholder

Manual Install

Download the OptimizelyListener file from:


In the project's root build.gradle, add the following:

allprojects {
    repositories {
        flatDir {
              dirs 'libs'

Include in your app's "libs" directory, and add the following to your project module's build.gradle:

dependencies {
    compile(name:'tealium-5.3.1', ext:'aar') // only required if you do not already have this reference
    compile(name:'tealium.optimizelylistener-1.0.0', ext:'aar')
    compile(name:'tealium.lifecycle-5.0.4', ext:'aar') // only required if you do not already have this reference and require lifecycle tracking

Maven Install

In your project's root gradle file, add the following maven repository:

maven {
    url "http://maven.tealiumiq.com/android/releases/"

In your project module gradle file, add the following maven dependency:

    compile 'com.tealium:library:5.3.1' //only required if you do not have this reference
    compile 'com.tealium:optimizelylistener:1.0'
    compile 'com.tealium:lifecycle:1.1' //only required if you do not already have this reference and require lifecycle tracking


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 initalized, so it makes sense to place the code here.

// 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() {
public void onStart(OptimizelyClient optimizely) {
// call this to init the Optimizely listener with a valid OptimizelyManager instance
// note that myOptlyManager is your own reference to a global OptimizelyManager instance, which has been previously instantiated
TealiumOptimizelyEventListener.init(TEALIUM_INSTANCENAME, myOptlyManager);
// activate experiment AFTER initializing the Tealium listener.
// tracking calls will be missed if not done in this order.
Variation v = optimizely.activate("tealiumtest", "userid");

Once you have initialized the module, no additional config is required. The module will now listen for notifications from the Optimizely SDK and pass the data to the Tealium SDK as required.


This module depends on the Optimizely X Android SDK, and your app will not compile if this SDK is not present in your project.


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

These events are captured by Tealilum with the following event names:

  •  tealium_event="Optimizely Experiment Started" - when the Optimizely SDK activates an experiment.
  •  tealium_event="Optimizely Event Tracked" - when the Optimizely SDK receives a custom event (generated by manually calling Optimizely's track method).

Data Layer Variables

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

Variable Scope Experiment Activation Event Tracking Description
optimizely_experiment_key Volatile (session) X X Optimizely experiment name (e.g. "Homescreen MVT")
optimizely_variation_key Volatile (session) X X Optimizely variation name (e.g. "Variation A")
optimizely_user_id Volatile (session) X X Optimizely user ID (e.g. "alice@tealium.com")
optimizely_event_key Hit (single event) X X Optimizely event name (e.g. "purchase")
optimizely_event_value Hit (single event) X X Optimizely event value (e.g. "123" - integer values only)
optimizely_XXX Hit (single event) X X Optimizely custom attribute prefix. All custom attributes are prefixed with "optimizely_" and passed directly to Tealium

Overriding default variable names (optional)

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

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>;