Analytics Swift Optimizely Full Stack Plugin
Add OptimizelyFullStack session tracking support to your applications via this plugin for Analytics-Swift
This plugin simply adds session data for OptimizelyFullStack, and events are sent via Cloud Mode.
- 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
- Finally, define any
attributesin your Optimizely dashboard, and to associate
metricswith the appropriate Optimizely Experiments. Segment maps
trackevent names to Optimizely
eventNamecorresponds to an experiment
metric. In addition, Segment maps
Adding the dependency
In the Xcode
File menu, click
Add Packages. You’ll see a dialog where you can search for Swift packages. In the search field, enter the URL to this repo.
You’ll then have the option to pin to a version, or specific branch, as well as which project in your workspace to add it to. Once you’ve made your selections, click the
Add Package button.
Open your Package.swift file and add the following do your the
.package( name: "Segment", url: "https://github.com/segment-integrations/analytics-swift-integration-optimizely-full-stack.git", from: "1.0.0" ),
Using the Plugin in your App
Open the file where you setup and configure the Analytics-Swift library. Add this plugin to the list of imports.
import Segment import SegmentOptimizelyFullStack // <-- Add this line
Just under your Analytics-Swift library setup, call
analytics.add(plugin: ...) to add an instance of the plugin to the Analytics timeline.
let analytics = Analytics(configuration: Configuration(writeKey: "<YOUR WRITE KEY>") .flushAt(3) .trackApplicationLifecycleEvents(true)) analytics.add(plugin: OptimizelyFullStack(optimizelyKey: "<Optimizely Production Key>"))
Please Note : Here “optimizelyKey” you can get from Optimizely Dashboard Settings. You can use development or production SDK key respectively.
Your events will now be given OptimizelyFullStack session data and start flowing to OptimizelyFullStack via Cloud Mode.
Upon invocation of a Segment
track event, Segment maps the event to an Optimizely
- 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
Segment also handles the following mapping:
trackevent name to Optimizely
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
Note: Custom Event Tags in Optimizely, which include all Event Tags except
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
userId is unavailable by setting
Invoking a Segment
identify event sets Segment
traits as Optimizely
attributes are sent downstream to Optimizely upon invocation of the next Segment
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.
Follow these instructions on how to set up Engage and Optimizely:
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
Questions? Problems? Need more info? Contact Segment Support for assistance!