HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In
Hey! These docs are for version 2.1.0-full-stack, which is no longer officially supported. Click here for the latest version, 1.0!

Set up Mixpanel

If you are just getting started, read the Mixpanel Quick Start Guide.

Mixpanel supports two types of properties that you can use to segment data in their reports: Super Properties and People Properties. Each type of property captures a slightly different aspect of the events and users they describe, and they differ in the ways they can be used for reporting. For maximum flexibility in reporting, we will use both super properties and people properties like Mixpanel suggests.

In the example code below, we add an activate listener block callback. In the callback, we first set the super property and then the people property with Mixpanel.

import android.util.Log;
import com.mixpanel.android.mpmetrics.MixpanelAPI;
import com.optimizely.ab.config.Experiment;
import com.optimizely.ab.config.Variation;
import com.optimizely.ab.notification.NotificationListener;
import org.json.JSONException;
import org.json.JSONObject;

optimizelyManager.getOptimizely().getNotificationCenter().addNotificationListener(NotificationCenter.NotificationType.Activate, new ActivateNotificationListener() {
    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();

    // Mixpanel instance
    String projectToken = YOUR_PROJECT_TOKEN;
    MixpanelAPI mixpanel = MixpanelAPI.getInstance(this, projectToken);

    try {
      // "Super property" will be sent with all future track calls
      JSONObject props = new JSONObject();
      props.put("[Optimizely] " + experimentKey, variationKey);
    } catch (JSONException e) {
      Log.e("MYAPP", "Unable to add properties to JSONObject", e);

    // Set "People property" for the user
        "[Optimizely] " + experimentKey, variationKey);

    // Track impression event (optional)
        "[Optimizely] " + experimentKey + " - " + variationKey);
#import "Mixpanel/Mixpanel.h"

[optimizely.notificationCenter addActivateNotificationListener:^(OPTLYExperiment *experiment, NSString *userId, NSDictionary<NSString *,NSString *> *attributes, OPTLYVariation *variation, NSDictionary<NSString *,NSString *> *event) {
  // Mixpanel instance
  Mixpanel *mixpanel = [Mixpanel sharedInstance];

  NSString *propertyKey
    = [NSString stringWithFormat:@"[Optimizely] %@",
   registerSuperProperties:@{propertyKey: variation.variationKey}];

  // Set "People property" for the user
  [mixpanel.people set:@{propertyKey: variation.variationKey}];

  // Track impression event (optional)
  NSString *eventIdentifier
    = [NSString stringWithFormat:@"[Optimizely] %@ - %@",
  [mixpanel track:eventIdentifier];
import Mixpanel

optimizely?.notificationCenter?.addActivateNotificationListener({ (experiment, userId, attributes, variation, logEvent) in
  // Mixpanel instance
  let mixpanel : MixpanelInstance = Mixpanel.mainInstance()

  // "Super property" will be sent with all future track calls
  let propertyKey : String! = "[Optimizely] " + experiment.experimentKey
  mixpanel.registerSuperProperties([propertyKey: variation.variationKey])

  // Set "People property" for the user
  mixpanel.people.set(property: propertyKey, to: variation.variationKey)

  // Track impression event (optional)
  let eventIdentifier : String = "[Optimizely] "
  + experiment.experimentKey + " - " + variation.variationKey

We recommend using the same user ID with the following methods:

LanguageActivate Callback
Android- optimizelyClient.activate()
- mixpanel.alias()
- mixpanel.identify()
Objective-C- [optimizely activate]
- [mixpanel createAlias]
- [mixpanel identify]
Swift- optimizely.activate()
- mixpanel.createAlias()
- mixpanel.identify()

Next in the callback, we can optionally log an impression event that signifies that the Optimizely test was activated for the current user. You can use this event or another event you may already be tracking to calculate a conversion rate.

Compare results

When comparing Optimizely and Mixpanel results, remember to apply a date filter in Mixpanel to correspond with the dates your Optimizely test was running. People properties and super properties will remain set in Mixpanel even after your Optimizely test has stopped running.

Consistent user identity

Maintaining a consistent user identity across multiple sessions and devices can help ensure proper reporting. Mixpanel provides some guidelines for their platform.

Unsupported Platforms

Optimizely does not have a suggested solution for integrating Amplitude with our SDKs for these platforms:

  • C#
  • Java
  • Python
  • Ruby
  • JavaScript
  • Node
  • PHP