react-native-mixpanel icon indicating copy to clipboard operation
react-native-mixpanel copied to clipboard

possible to support tweaks for A/B tests?

Open ms88privat opened this issue 9 years ago • 11 comments

see https://mixpanel.com/help/reference/ios#tweaks

ms88privat avatar May 30 '16 07:05 ms88privat

I've been looking in to this, but a major problem seems to be that Tweaks can't be assigned dynamically.

My first approach was to wrap getExperiments and then add a method for getting Tweaks from JS, something like this (pseudo code):

RCT_METHOD(getTweaks){
     [mixpanel getTweaks];
}

RCT_METHOD_WITH_CALLBACK(getAB: name, defaulValue){
     NSString * abValue = MPTweak(name, defaultValue)
     callback(abValue)
}

This is not a valid approach tough, does anyone have any ideas on how to implement this?

Basically - the tweaks have to be explicitly set at compiletime.

raubas avatar Aug 05 '16 11:08 raubas

I also attempted to make this work this week but no success for the reason described Above. I'm talking to Mixpanel support to try to get more support for React-native.

In the meantime I just implemented the A/B test tweaks by creating a Bridge. This way I have to the different Variables in ObjectiveC, but I can get the value and do the rest of the logic in React Native. In case anyone still wants to use this library and Mixpanel Tweaks.

Jeanmsilva89 avatar Mar 20 '17 18:03 Jeanmsilva89

@Jeanmsilva89 Very interested, would you mind sharing? Couldn't find your fork. Thanks!

skleest avatar Apr 28 '17 19:04 skleest

Any update on this?

johnchourajr avatar Oct 27 '17 23:10 johnchourajr

From what I remember it is possible to define some variables and use them in RN, the thing is that you will need to define them beforehand - it is not possible to do dynamic A/B-tests. If that is fine my approach from above can be used (after a bit of refinement).

raubas avatar Oct 31 '17 08:10 raubas

@raubas can you give a snippet example of what you're doing with this?

johnchourajr avatar Nov 16 '17 18:11 johnchourajr

@raubas @Jeanmsilva89 same here, would love to see an example of how you did this

Gaia-Nutrition avatar Nov 20 '17 18:11 Gaia-Nutrition

Hi guys, ok so it was a while since I took a look at this.

But basically what I came up with:

(haven't tested though)

// MPTweakHelper.h
#import <React/RCTBridgeModule.h>

@interface MPTweakHelper: NSObject <RCTBridgeModule>
@end

// MPTweakHelper.m
//Also need to import mixpanel and handle getting the correct instance
#import "MPTweakHelper"
#import <React/RCTBridgeModule.h>

@implementation MPTweakHelper

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(getNumberOfLivesTweak:(RCTResponseSenderBlock)callback)
{
  NSInteger numLives = MPTweakValue(@"number of lives", 5);
  callback(@[[NSNull null], @(numLives)]);
}

@end
// MPTweakHelper.js
import { NativeModules } from 'react-native';
const  MPTweakHelper = MPTweakHelper;
MPTweakHelper.getNumberOfLivewsTwek((err, tweakVal) => console.log(`numberOfLives: ${tweakVal}`);

The reason I didn't use it and really can't be solved (easily) in this lib is because all the tweak-values needs to be hardcoded (key and default value). So it will be specific to each installation.

What I wanted was to be able to get a tweak dynamically, basically setting key and default value from JS and the use MP to get a tweaked value. However this is not possible :(

raubas avatar Nov 21 '17 10:11 raubas

Is there an update on this? Support for A/B Testing would be amazing!

dilee716 avatar Mar 08 '18 21:03 dilee716

@raubas when you say

//Also need to import mixpanel and handle getting the correct instance

Is there anything other than #import <Mixpanel/MPTweakInline.h> that you are picturing? I've got the setup returning a value, but unfortunately the tweak value does not appear in my mixpanel console. Leads me to believe I am not connecting correctly (though the React Native library itself is configured with the token properly).

RobinJayaswal avatar Jul 19 '18 04:07 RobinJayaswal

Yeah it is kind of tricky - you need to make sure that you are referencing the same instance in the js context as you are on the native side. I kind of gave up in this idea since it introduced too much complexity. But from what I remember, the mixpanel instance with your key gets initiated when the js-bundle gets loaded. You need to set this in native code as well - otherwise you are setting the tweak values in a different mp instance..

raubas avatar Jul 19 '18 07:07 raubas