Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Set up Mixpanel

This topic describes how you can integrate Mixpanel with Optimizely.

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);

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

LanguageActivate Callback
Android- optimizelyClient.activate()
- mixpanel.alias()
- 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 various best practices for their platform.

Unsupported Platforms

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

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