react-native-mixpanel
react-native-mixpanel copied to clipboard
possible to support tweaks for A/B tests?
see https://mixpanel.com/help/reference/ios#tweaks
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.
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 Very interested, would you mind sharing? Couldn't find your fork. Thanks!
Any update on this?
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 can you give a snippet example of what you're doing with this?
@raubas @Jeanmsilva89 same here, would love to see an example of how you did this
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 :(
Is there an update on this? Support for A/B Testing would be amazing!
@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).
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..