Set up Amplitude
This topic describes how you can enrich Amplitude reports with Optimizely test information.
Note
This is a third-party integration and is not an Optimizely subprocessor. See Optimizely's Third-Party Add-Ons & Platform Integration Terms.
If you are getting started, read the Amplitude documentation.
Amplitude features two types of properties that you can use to enrich and segment their reports with Optimizely test information:
-
Event properties describe a single event, so they must be added to each logged event. The Amplitude SDK and backend do not automatically add event properties to future events. For this reason, user properties are less complex to work with than event properties.
-
User properties describe a user across all logged events. After you set a user property, Amplitude applies it in their backend to subsequent recorded events until someone changes the property.
The example code below demonstrates an activate _callback. In the callback, the code shows Amplitude's _identify interface setting a new user property, which includes the experiment key and variation key. The user property should immediately propagate to the Amplitude backend and be visible in their dashboard. To compare the performances of variations in a test, create a new segment for each variation.
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.ActivateNotificationListener;
import com.optimizely.ab.notification.NotificationCenter;
OptimizelyClient optimizelyClient = optimizelyManager.getOptimizely();
// Add a Activate listener
int notificationId = optimizelyClient.getNotificationCenter().addNotificationListener(NotificationCenter.NotificationType.Activate, new ActivateNotificationListener() {
@Override
public void onActivate(@Nonnull Experiment experiment, @Nonnull String userId, @Nonnull Map<String, String> attributes, @Nonnull Variation variation, @Nonnull LogEvent event) {
String experimentKey = experiment.getKey();
String variationKey = variation.getKey();
// Set "user property" for the user
Identify identify = new Identify().set(
"[Optimizely] " + experimentKey, variationKey);
AmplitudeClient amplitudeClient = Amplitude.getInstance();
amplitudeClient.identify(identify);
// Track impression event (optional)
amplitudeClient.logEvent(
"[Optimizely] " + experimentKey + " - " + variationKey);
}
});
function onActivate(activateObject) {
const experimentKey = activateObject.experiment['key'];
const variationKey = activateObject.variation['key'];
// Set "user property" for the user
const identify = new amplitude.Identify().set(
'[Optimizely] ' + experimentKey,
variationKey,
);
amplitude.identify(identify);
// Track impression event (optional)
amplitude.logEvent('[Optimizely] ' + experimentKey + ' - ' + variationKey);
}
// Add an ACTIVATE notification listener
const activateId = optimizelyClient.notificationCenter.addNotificationListener(
optimizelyEnums.NOTIFICATION_TYPES.ACTIVATE,
onActivate,
);
#import "Amplitude.h"
#import "AMPIdentify.h"
[optimizely.notificationCenter addActivateNotificationListener:^(OPTLYExperiment *experiment, NSString *userId, NSDictionary<NSString *,NSString *> *attributes, OPTLYVariation *variation, NSDictionary<NSString *,NSString *> *event) {
NSString *propertyKey
= [NSString stringWithFormat:@"[Optimizely] %@",
experiment.experimentKey];
AMPIdentify *identify
= [[AMPIdentify identify] set:propertyKey
value:variation.variationKey];
[[Amplitude instance] identify:identify];
// Track impression event (optional)
NSString *eventIdentifier
= [NSString stringWithFormat:@"[Optimizely] %@ - %@",
experiment.experimentKey,
variation.variationKey];
[[Amplitude instance] logEvent:eventIdentifier];
}];
import Amplitude_iOS
let activateNotificationId = optimizely?.notificationCenter?.addActivateNotificationListener({ (experiment, userId, attributes, variation, logEvent) in
// Set "user property" for the user
let propertyKey : String! = "[Optimizely] " + experiment.experimentKey
let identify : AMPIdentify = AMPIdentify()
identify.set(propertyKey, value:variation.variationKey as NSObject!)
// Track impression event (optional)
let eventIdentifier : String = "[Optimizely] "
+ experiment.experimentKey + " - " + variation.variationKey
Amplitude.instance().logEvent(eventIdentifier)
})
In the preceding example code, look for the following items.
Language | Activate Callback | Identify interface |
---|---|---|
Android | ActivateNotificationListener.onActivate | Identify |
JavaScript | onActivate | Identify |
Objective-C | activate | AMPIdentify |
Swift | activate | AMPIdentify |
If you want, you can log an impression event in the callback to signify that the Optimizely test was activated for the current user. You can later use this event (or another event you may already be tracking) to calculate a conversion rate.
Compare results
When comparing numbers between Optimizely and Amplitude results, remember to apply a date filter in Amplitude that corresponds with the dates your Optimizely test was running. Note that user properties remain set in Amplitude, regardless of whether your Optimizely test is running.
Alternative solution for Optimizely Enterprise accounts
You can use Amplitude's Behavioral Cohort Analysis, which can segment on the impression event tracked in the example code.
Unsupported platforms
Optimizely does not have a suggested solution for integrating Amplitude with our SDKs for these platforms:
- Agent
- C#
- Go
- Java
- Node
- PHP
- Python
- Ruby
Updated 5 months ago