Analytics Kotlin Optimizely Full Stack Plugin
Getting Started
- In your Segment source dashboard, enable the “Optimizely Full Stack” destination (not the “Optimizely Web” destination).
- Include your Optimizely project’s
datafileURL in your Segment settings. - Create a native Optimizely instance in your server environment so you can access Optimizely decisioning methods like
activate,isFeatureEnabled. - Finally, define any
eventsandattributesin your Optimizely dashboard, and to associatemetricswith the appropriate Optimizely Experiments. Segment mapstrackevent names to OptimizelyeventName- theeventNamecorresponds to an experimentmetric. In addition, Segment mapstrackeventcontext.traitsto Optimizelyattributes.
Add Optimizely Full integration to your applications via this plugin for Analytics-Kotlin.
Adding the dependency
To install the Segment-Optimizely-Full Stack integration, simply 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
Open the file where you setup 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.
manager = OptimizelyManager.builder()
.withSDKKey("<WRITE_YOUR_OPTIMIZELY_SDK-KEY>")
.build(applicationContext)
Just under your Analytics-Kotlin library setup, call analytics.add(plugin = ...) to add an instance of the plugin to the Analytics timeline.
analytics = Analytics("<YOUR WRITE KEY>", applicationContext) {
this.flushAt = 3
this.trackApplicationLifecycleEvents = true
}
analytics.add(plugin = OptimizelyFullDestinaton(optimizelyManager = manager))
Your events will now begin to flow to Optimizely-Full Stack in device mode.
Track
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
metricset up in the Optimizely dashboard; - If the experiment
metricis 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
trackevent name to OptimizelyeventName. - Segment
trackeventpropertiesto OptimizelyeventTags.
revenue values should be passed as a Segment property. The value should be an integer and represent the value in cents, so, for example, $1 should be represented by 100.
Note: Custom Event Tags in Optimizely, which include all Event Tags except revenue and value, are not displayed on the Optimizely results page, however they are available in a Data Export 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.
Identify
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
Notification listeners are not available for Segment track events when implementing Optimizely using Segment using cloud-mode. Notification listeners are still available with any native call invoked from your Optimizely client instance.
Engage
Follow these instructions on how to set up Engage and Optimizely:
GDPR Support
Segment supports deleting/suppressing users in Optimizely using the Segment app. In order to do this however, you will need to create a Personal Access Token in Optimizely and provide it as the value of the Access Token setting.
This page was last modified: 21 Apr 2023
Need support?
Questions? Problems? Need more info? Contact Segment Support for assistance!