The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideAPI Reference
Dev guideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunitySubmit a ticketLog In

Set up Mixpanel

Describes how to enrich Mixpanel with Optimizely Feature Experimentation data.

📘

Note

See Optimizely's Third-Party Add-Ons & Platform Integration Terms.

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, the integration supports super properties and people properties, as Mixpanel suggests.

📘

Note

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

The following Andreoid example code adds an activate listener block callback. In the callback, it first sets the super property and then the people property with Mixpanel.

The JavaScript example code listens for A/B test decisions made by Feature Experimentation and logs relevant experiment information to 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() {
    @Override
    public void onActivate(Experiment experiment, String userId, Map<String, ?> attributes, Variation variation, 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);
      mixpanel.registerSuperProperties(props);
    } catch (JSONException e) {
      Log.e("MYAPP", "Unable to add properties to JSONObject", e);
    }

    // Set "People property" for the user
    mixpanel.getPeople().set(
        "[Optimizely] " + experimentKey, variationKey);

    // Track impression event (optional)
    mixpanel.track(
        "[Optimizely] " + experimentKey + " - " + variationKey);
  }
});
// Notification Listeners execute whenever a bucketing decision is made on a visitor for an A/B Test or Targeted Delivery.
// https://docs.developers.optimizely.com/feature-experimentation/docs/set-up-notification-listener-javascript
const onDecision = ({ type, userId, attributes, decisionInfo }) => {
  // Check if a decision event was dispatched. This will only happen if the visitor is put into an A/B Test.
  if (decisionInfo['decisionEventDispatched']) {
    // Get experiment bucketing info
    let experimentKey = "[Optimizely] " + decisionInfo['ruleKey']
    let variationKey = decisionInfo['variationKey']
    let decisionObject = {};
    decisionObject[experimentKey] = variationKey;
    
    // https://docs.mixpanel.com/docs/data-structure/property-reference
    // Set Mixpanel Super Property with experiment bucketing info. This will include experiment bucketing info with all future track calls.
    mixpanel.register(decisionObject);
    
    // (Optional) Set Mixpanel User Profile Property with experiment bucketing info.
    mixpanel.people.set(decisionObject);
    
    // (Optional) Set Mixpanel experiment_viewed event with experiment bucketing info.
    mixpanel.track("experiment_viewed", decisionObject);
}
  
const notificationId = optimizelyClient.notificationCenter.addNotificationListener(enums.NOTIFICATION_TYPES.DECISION, onDecision);

You should use the same user ID with the following methods:

LanguageActivate Callback
Android- optimizelyClient.activate() - mixpanel.alias() - mixpanel.identify()

Next, in the callback, you can optionally log an impression event that signifies that the Optimizely Feature Experimentation 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 Feature Experimentation and Mixpanel results, remember to apply a date filter in Mixpanel to correspond with the dates your Optimizely Feature Experimentation test was running. People properties and super properties will remain set in Mixpanel even after your Feature Experimentation 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.

Additional SDKs

Refer to Mixpanel's documentation and Feature Experimentation's decision notification listener documentation to set up this integration with other relevant SDKs.