Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Analytics Kotlin Optimizely Full Stack Plugin


Getting started

getting-started page anchor
  1. In your Segment source dashboard, enable the Optimizely Full Stack *destination.
  2. Include your Optimizely project's datafile URL in your Segment settings.
  3. Create a native Optimizely instance in your server environment so you can access Optimizely decisioning methods like activate, isFeatureEnabled.
  4. Finally, define any events(link takes you to an external page) and attributes(link takes you to an external page) in your Optimizely dashboard, and to associate metrics with the appropriate Optimizely Experiments. Segment maps Track event names to Optimizely eventName - the eventName corresponds to an experiment metric. In addition, Segment maps Track event context.traits to Optimizely attributes.

Add Optimizely Full integration to your applications using this plugin for Analytics-Kotlin(link takes you to an external page).


To install the Segment-Optimizely-Full Stack integration, add this line to your gradle file:

implementation 'com.segment.analytics.kotlin.destinations:optimizely-full-stack:<latest_version>'

Or the following for Kotlin DSL:

implementation('com.segment.analytics.kotlin.destinations:optimizely-full-stack:<latest_version>')

Using the plugin in your app

using-the-plugin-in-your-app page anchor

Open the file where you set up and configure the Analytics-Kotlin library. Add this plugin to the list of imports.

import com.segment.analytics.kotlin.destinations.optimizelyfull.OptimizelyFullDestinaton

Since the Optimizely Manager should be initialized as soon as possible in your application subclass, we leave it up to you to create this instance. You must then pass it to the Plugin.

1
manager = OptimizelyManager.builder()
2
.withSDKKey("<WRITE_YOUR_OPTIMIZELY_SDK-KEY>")
3
.build(applicationContext)

Under your Analytics-Kotlin library setup, call analytics.add(plugin = ...) to add an instance of the plugin to the Analytics timeline.

1
analytics = Analytics("<YOUR WRITE KEY>", applicationContext) {
2
this.flushAt = 3
3
this.trackApplicationLifecycleEvents = true
4
}
5
analytics.add(plugin = OptimizelyFullDestinaton(optimizelyManager = manager))

Your events will now begin to flow to Optimizely-Full Stack in device-mode.

Track

track page anchor

Upon invocation of a Segment Track event, Segment maps the event to an Optimizely Track event:

  • If the Segment event name matches exactly the name of an active experiment metric set up in the Optimizely dashboard;
  • If the experiment metric is associated with a running experiment;
  • If the current user is activated in a running experiment with the associated metric.

Segment also handles the following mapping:

  • Segment Track event name to Optimizely eventName.
  • Segment Track event properties to Optimizely eventTags.

revenue values should be passed as a Segment property. The value should be an integer and represent the value in cents, for example, $1 should be represented by 100.

(information)

Custom Event Tags aren't displayed on the Optimizely results page

Optimizely's Custom Event Tags(link takes you to an external page), which include all Event Tags except revenue and value, aren't displayed on the Optimizely results page. However, these tags are available in a Data Export(link takes you to an external page) report. Event Tags can be strings, integers, floating point numbers, or boolean values. Optimizely rejects events with any other data types (for example, arrays).

Segment defaults to identifying users with their anonymousId. Enabling "Use User ID" setting in your Segment dashboard means that only Track events triggered by identified users are passed downstream to Optimizely. You may optionally fall back to anonymousId when userId is unavailable by setting fallbackToAnonymousId to true.

Invoking a Segment Identify event sets Segment traits as Optimizely attributes. The attributes are sent downstream to Optimizely upon invocation of the next Segment Track event.

Notification listeners aren't available for Segment Track events when implementing Optimizely using Segment using cloud-mode. Notification listeners(link takes you to an external page) are still available with any native call invoked from your Optimizely client instance.


See Optimizely's instructions on how to set up Engage and Optimizely at Using Segment Personas and Optimizely Full Stack for Omnichannel Experiments(link takes you to an external page).


Segment supports deleting or suppressing users in Optimizely using the Segment app. To do this, however, you need to create a Personal Access Token(link takes you to an external page) in Optimizely and provide it as the value of the Access Token setting.