Configure Amplitude
Enrich Amplitude reports with your Optimizely Feature Experimentation experiment and targeted delivery information.
NoteThis is a third-party integration and is not an Optimizely subprocessor. See Optimizely's Third-Party Add-Ons & Platform Integration Terms.
Prerequisites
Start by reading the Amplitude Get Started documentation.
Amplitude
Amplitude offers two properties types to enrich and segment reports with your Feature Experimentation experiment and targeted delivery information.
- Event properties – Describes a single event and must be added to each logged event. Amplitude does not automatically apply event properties to future events, making them more complex to manage than user properties. See Event properties in the Amplitude documentation.
- User properties – Describes a user across all logged events. When set, Amplitude applies user properties to all subsequent recorded events until you update them. See User properties in the Amplitude documentation.
Example Decide callback
Decide callbackThe following code examples show how to set an Amplitude user property and track an optional impression event. This configuration sends the flag key and variation key to Amplitude as user properties and logs events in the Amplitude dashboard. Click the different languages in the heading to view the code for that language.
import Amplitude_iOS
let activateNotificationId = notificationCenter.addDecisionNotificationListener(decisionListener: { (type, userId, attributes, decisionInfo) in
let isEventDispatched = decisionInfo["decisionEventDispatched"] as? Bool
if type == "flag", isEventDispatched == true {
let variationKey = decisionInfo["variationKey"] as! String
let propertyKey : String! = "[Optimizely] " + decisionInfo["flagKey"]
let identify : AMPIdentify = AMPIdentify()
identify.set(propertyKey, value: variationKey)
// Track impression event (optional)
let eventIdentifier : String = "[Optimizely] "
+ decisionInfo["flagKey"] + " - " + variationKey
Amplitude.instance().logEvent(eventIdentifier)
}
})
import com.amplitude.api.Amplitude;
import com.amplitude.api.AmplitudeClient;
import com.amplitude.api.Identify;
import com.optimizely.ab.config.Experiment;
import com.optimizely.ab.config.Variation;
import com.optimizely.ab.notification.DecisionNotification;
import com.optimizely.ab.notification.NotificationCenter;
OptimizelyClient optimizelyClient = optimizelyManager.getOptimizely();
// Add a Decision listener
int notificationId = optimizelyClient.getNotificationCenter().addNotificationHandler(DecisionNotification.class, decisionNotificationHandler -> {
Map<String, ?> decisionInfo = decisionNotificationHandler.getDecisionInfo();
Boolean isEventDispatched = (Boolean) decisionInfo.get("decisionEventDispatched");
if (decisionNotificationHandler.getType().equals("flag") && (isEventDispatched != null && isEventDispatched)) {
String variationKey = (String) decisionInfo.get("variationKey");
String propertyKey = "[Optimizely] " + decisionInfo.get("flagKey");
// Set "user property" for the user
Identify identify = new Identify().set(
propertyKey, variationKey);
AmplitudeClient amplitudeClient = Amplitude.getInstance();
amplitudeClient.identify(identify);
// Track impression event (optional)
amplitudeClient.logEvent(
propertyKey + " - " + variationKey);
}
});import com.amplitude.api.Amplitude;
import com.amplitude.api.AmplitudeClient;
import com.amplitude.api.Identify;
import com.optimizely.ab.config.Experiment;
import com.optimizely.ab.config.Variation;
import com.optimizely.ab.notification.DecisionNotification;
import com.optimizely.ab.notification.NotificationCenter;
var notificationId = optimizelyClient.notificationCenter.addNotificationHandler(
DecisionNotification::class.java,
NotificationHandler{ handler: DecisionNotification? ->
var decisionInfo = handler?.decisionInfo
var type = handler?.type
var isEventDispatched: Boolean? = decisionInfo?.get("decisionEventDispatched") as? Boolean
if ((isEventDispatched == true) && (type == "flag")) {
var variationKey: String? = decisionInfo?.get("variationKey") as? String
var propertyKey: String? = decisionInfo?.get("propertyKey") as? String
val identify = Identify().set(propertyKey, variationKey)
val amplitudeClient = Amplitude.getInstance()
amplitudeClient.identify(identify)
// Track impression event (optional)
amplitudeClient.logEvent(propertyKey + " - " + variationKey)
}
}
)
import {
createPollingProjectConfigManager,
createInstance,
NOTIFICATION_TYPES
} from "@optimizely/optimizely-sdk";
import * as amplitude from '@amplitude/analytics-browser';
amplitude.init('<AMPLITUDE_API_KEY>');
const projectConfigManager = createPollingProjectConfigManager({
sdkKey: "YOUR_SDK_KEY",
});
const optimizely = createInstance({
projectConfigManager,
});
const onDecision = ({ type, decisionInfo }) => {
const { decisionEventDispatched, variationKey, flagKey } = decisionInfo;
if (type === 'flag' && decisionEventDispatched) {
const propertyKey = `[Optimizely] ${flagKey}`;
const identify = new amplitude.Identify().set(propertyKey, variationKey);
amplitude.identify(identify);
// Track impression event (optional)
amplitude.logEvent(`[Optimizely] ${flagKey} - ${variationKey}`);
}
};
// Add a DECISION notification listener
const notificationId = optimizely.notificationCenter.addNotificationListener(
NOTIFICATION_TYPES.DECISION,
onDecision
);Summary of key elements
| Language | Activate callback | Identify interface |
|---|---|---|
| Android (Java and Kotlin) | decisionNotificationHandler | Identify |
| JavaScript | onActivate | Identify |
| Swift | activate | AMPIdentify |
If needed, log an impression event in the callback to signify that the Feature Experimentation test activated. Use these events to calculate conversion rates.
Compare results
To compare Feature Experimentation results with Amplitude, apply a date filter in Amplitude that matches the experiment or targeted delivery dates.
NoteUser properties persist in Amplitude even when your Feature Experimentation test is not running.
Unsupported SDKs
The following SDKs do not have a suggested solution for integrating Feature Experimentation with Amplitude:
- Agent
- C#
- Go
- Java
- Node
- PHP
- Python
- Ruby
Updated 3 days ago
