Sen
Sen

Reputation: 21

How to use Mixpanel to assign AB testing bucket for iOS

I am using mixpanel for event tracking on iOS. I want to get started on using AB testing.

Say X% of user gets shown an alert, as bucket 1; and Y% of user doesn't get the alert, as bucket 2;

Below is a sample code that I tried to use MPTweakValue to achieve the bucket assignment:

#import "Mixpanel/MPTweakInline.h"
...
int bucketId = MPTweakValue(@"bucket", 1);
if (bucketId == 1) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Welcome to Sample App" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil];
        [alert show];
    } else {
        //do nothing;
    }

I want to get every logic in code (the AB testing page on Mixpanel webpage is confusing to me since it focuses on UI change).

I cannot find anywhere from mixpanel to tweak the value for different users, where did I do wrong? Should I use something else to assign bucket instead of using MPTweakValue?

Upvotes: 2

Views: 1540

Answers (3)

Mieszczańczyk S.
Mieszczańczyk S.

Reputation: 957

This is going to be deprecated on 1st January 2022: https://mixpanel.com/blog/why-were-sunsetting-messaging-and-experiments/

Upvotes: 0

nca
nca

Reputation: 445

Unfortunately mixpanel doesn't allow us to configure specific result for particular user.

It is upto mixpanel to decide which bucket user will fall into, developer has no hold on this decision.

But if you turnoff the experiment, your tweak will return the default value which you used to configure the tweak.

Upvotes: 0

ohad serfaty
ohad serfaty

Reputation: 654

Unfortunately the Mixpanel documentation and the way that they chose to implement it is very confusing. It took me a while to wrap my head around it but eventually it worked. The fact that they let you tweak the UI can be confusing, The crucial point and the reason why you most of the time you won't see your developer tweaks is that the tweaks code have to actually run before you press 4 fingers to create an experiment. Here's a bit of explanation on what I did to make it work :

  1. The first thing you should do is to make the Mixpanel iphone "Hello world" app work with your mixpanel account. You can find it here :

https://github.com/mixpanel/mixpanel-iphone/tree/master/HelloMixpanel

There's also a brief youtube video explaining what the process is for creating an experiment :

https://www.youtube.com/watch?v=S6An3h2-kqQ

then :

  • run "pod install"
  • in the mixpanel web app, open a new mixpanel project so that it doesn't mess your dev or production project
  • in ViewController.m, change the mixpanel token to the new project token

    1. Run the HelloMixpanel app on your simulator, and go to the A/B testing tab. Follow their instructions ("With your app open, press the Option key, click and hold in the simulator for 5 seconds.") and you'll see on the right, in the "developer tweaks" section, that you have multiple options to choose from.

    2. You can apply that same logic to your own application, but note that you may need to call this method once in a while to sync up the experiments:

    Mixpanel.sharedInstance().joinExperimentsWithCallback()

The way that mixpanel works in the background, it would send whatever tweaks you have that had run code till the point where you start planning the experiments, so you need to make sure that the MPTweakValue() lines run before you plan the experiments. Mixpanel maintains a tweaks storage, and every time you press 4 fingers to connect to mixpanel it would send all the tweaks that it learned of so far.

Upvotes: 1

Related Questions