Skip to contentSkip to navigationSkip to topbar
On this page
Looking for more inspiration?Visit the
(information)
You're in the right place! Segment documentation is now part of Twilio Docs. The content you are used to is still here—just in a new home with a refreshed look.

Analytics Swift Optimizely Full Stack Plugin


Add OptimizelyFullStack session tracking support to your applications using this plugin for Analytics-Swift(link takes you to an external page)

(warning)

This plugin adds session data only

This plugin adds session data for OptimizelyFullStack, and events are sent using Cloud Mode.


Getting started

getting-started page anchor
  1. In your Segment source dashboard, enable the "Optimizely Full Stack" destination (not the "Optimizely Web" 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.

Using Xcode

using-xcode page anchor

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:

https://github.com/segment-integrations/analytics-swift-integration-optimizely-full-stack

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 to your the dependencies section:

1
.package(
2
name: "Segment",
3
url: "https://github.com/segment-integrations/analytics-swift-integration-optimizely-full-stack.git",
4
from: "1.0.0"
5
),

Using the plugin in your app

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

Open the file where you setup and configure the Analytics-Swift library. Add this plugin to the list of imports.

1
import Segment
2
import SegmentOptimizelyFullStack // <-- Add this line

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

1
let analytics = Analytics(configuration: Configuration(writeKey: "<YOUR WRITE KEY>")
2
.flushAt(3)
3
.trackApplicationLifecycleEvents(true))
4
analytics.add(plugin: OptimizelyFullStack(optimizelyKey: "<Optimizely Production Key>"))
(information)

Generating your Optimizely SDK Key

Generate your optimizelyKey from the Optimizely Dashboard Settings. You can use a development or production SDK key.

Your events will now be given OptimizelyFullStack session data and start flowing to OptimizelyFullStack in Cloud Mode.

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, so, for example, $1 should be represented by 100.

(information)

Custom Event Tags are not 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, are not 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 are not 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.


Follow Optimizely's instructions on how to set up Engage and Optimizely:

Using Segment Personas and Optimizely Full Stack for Omnichannel Experiments(link takes you to an external page)


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(link takes you to an external page) in Optimizely and provide it as the value of the Access Token setting.