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 mParticle

This topic describes how to send Optimizely experiment information from your Android and iOS apps to mParticle for further analysis.

This integration uses the Optimizely ACTIVATE notification listener and the Activate method or the TRACK notification listener and the Track method. When either method is called, this triggers the appropriate notification listener to send an event containing user, experiment, and variation data as input to mParticle. Once the integration is complete, you can expect to see the event in your Optimizely input feed on the mParticle Live Stream dashboard within 1 minute.

Before setting up Optimizely as input data for mParticle, we recommend that you review mParticle’s documentation on the Optimizely integration.

mParticle and Android

If you’re getting started, read mParticle Getting Started guide for the Android SDK.

Step 1: Prerequisites

  • Make sure that the required experiment is running in Optimizely.
  • Install the mParticle SDK with the additional Optimizely kit on the Android app.

Step 2: Enable the integration

The example code below sends an ACTIVATE notification listener that contains information about the user, experiment, and variation to mParticle in an event called Experiment Viewed.

📘

Note

You can customize the event name and also specify which event tags are included the event payload.

import com.mparticle.MParticle;
 
OptimizelyClient optimizelyClient = optimizelyManager.getOptimizely();
// Add an Activate listener
int notificationId = optimizelyClient.getNotificationCenter().addNotificationListener(NotificationCenter.NotificationType.Activate, new ActivateNotificationListener() {
  @Override
  public void onActivate(Experiment experiment,
                    String userId,
                    Map<String, String> attributes,
                    Variation variation) {
 
    String experimentId = experiment.getId();
    String experimentKey = experiment.getKey();
    String variationId = variation.getId();
    String variationKey = variation.getKey();
 
    Map<String, String> eventInfo = new HashMap<String, String>(2);
    eventInfo.put("experimentId", experimentId);
    eventInfo.put("experimentName", experimentKey);
    eventInfo.put("variationId", variationId);
    eventInfo.put("variationName", variationKey);
 
   MPEvent event = new MPEvent.Builder("Experiment Viewed",     EventType.Transaction)
                .duration(100)
                .info(eventInfo)
                .category("AB Test")
                .build();
 
MParticle.getInstance().logEvent(event);
 
  }
});

mParticle and iOS

If you’re getting started, read the mParticle Getting Started guide for the iOS SDK.

Step 1: Prerequisites

  • Make sure that the required experiment is running correctly in Optimizely.
  • Install the mParticle SDK with the additional Optimizely kit on the iOS app.

Step 2: Enable the integration

The example code below sends an ACTIVATE notification listener that contains information about the user, experiment, and variation to mParticle in an event called Experiment Viewed.

📘

Note

You can customize the event name and also specify which event tags are included the event payload.

@import mParticle_Apple_SDK;
 
// Conditionally activate an experiment for the provided user, can use mParticle ids 
OPTLYVariation *variation = [optimizely activate:@"my_experiment" 
                                          userId:[MParticle sharedInstance].identity.deviceApplicationStamp];
 
// mParticle event
MPProduct *product = [[MPProduct alloc] initWithName:@"Foo name"
                                                 sku:@"Foo sku"
                                            quantity:@4
                                               price:@100.00];
MPTransactionAttributes *attributes = [[MPTransactionAttributes alloc] init];
attributes.transactionId = @"foo-transaction-id";
// mapped to Optimizely as 45000 cents
attributes.revenue = @450.00;
attributes.tax = @30.00;
attributes.shipping = @30;
 
MPCommerceEventAction action = MPCommerceEventActionPurchase;
MPCommerceEvent *event = [[MPCommerceEvent alloc] initWithAction:action
                                                         product:product];
 
// mapped to Optimizely as a custom event name
[event addCustomFlag:@"custom revenue event name"
             withKey:MPKitOptimizelyEventName];
event.transactionAttributes = attributes;
[[MParticle sharedInstance] logCommerceEvent:event];
 
 
// notification listener that is bound to activate() and sends an event to mParticle with the experiment and variation information.
 
[optimizely.notificationCenter addActivateNotificationListener:^(OPTLYExperiment *experiment, NSString *userId, NSDictionary<NSString *,NSString *> *attributes, OPTLYVariation *variation, NSDictionary<NSString *,NSString *> *event) {
     
    MPEvent *event = [[MPEvent alloc] initWithName:@"Experiment Viewed"
                                          type:MPEventTypeOther];
     NSDictionary *eventInfo = @{
           @"experimentId" : [experiment experimentId],
           @"experimentName" : [experiment experimentKey],
           @"variationId" : [variation variationId],
           @"variationName" : [variation variationKey]
           };
      [[MParticle sharedInstance] logEvent:event];
 
}];
import mParticle_Apple_SDK
 
// Optimizely notification listener for activate() 
let activateNotificationId = optimizely?.notificationCenter?.addActivateNotificationListener({ (experiment, userId, attributes, variation, logEvent) in
        let eventInfo = ["experimentId": experiment.experimentId as Any,
                  "experimentName": experiment.experimentKey as Any,
                  "variationId": variation.variationId as Any,
                  "variationName": variation.variationKey as Any]
    
       MParticle.sharedInstance().logEvent("Experiment Viewed", eventType: MPEventType.other, eventInfo: eventInfo)
 
})

Q/A and troubleshooting

To verify the integration is working, check the Optimizely input feed of the mParticle Live Stream dashboard. You should see the sent event (Experiment Viewed, or your customized name) within 3-5 minutes after completing the integration. If you don’t see the event, make sure your experiment is running correctly in Optimizely.

📘

Note

mParticle uses dollars and Optimizely uses cents. mParticle handles the conversion to dollars.

Unsupported platforms

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

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