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

Set up Mixpanel

This topic describes how to enrich Mixpanel with Optimizely Feature Experimentation data.

📘

Note

If you are 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 as 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() {
    @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);
  }
});

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 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 Optimizely 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.

Unsupported Platforms

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

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