Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A component for rendering A/B tests in React Native

NotificationsYou must be signed in to change notification settings

lwansbrough/react-native-ab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A component for rendering A/B tests in React Native.

Getting started

  1. npm install react-native-ab@latest --save

Obtaining your metrics

Once you've got your A/B tests set up, you'll need a place to send the data. Check out these libraries for A/B testing:

Usage

All you need is torequire thereact-native-ab module and then use the provided tags (<Experiment>, and<Variant>).

varReact=require('react-native');var{  AppRegistry,  StyleSheet,  Text,  View,  TouchableHighlight}=React;var{ Experiment, Variant}=require('react-native-ab');varrnabtest=React.createClass({render:function(){return(<Viewstyle={styles.container}><TouchableHighlightonPress={this._resetExperiment}><View><Experimentref="welcomeExperiment"name="welcome-message"onChoice={(test,variant)=>console.log(test,variant)}><Variantname="standard"><Textstyle={styles.welcome}>                  Welcome to React Native!</Text></Variant><Variantname="friendly"><Textstyle={styles.welcome}>                  Hey there! Welcome to React Native!</Text></Variant><Variantname="western"><Textstyle={styles.welcome}>                  Howdy, partner! This here is React Native!</Text></Variant></Experiment></View></TouchableHighlight><Textstyle={styles.instructions}>          To get started, edit index.ios.js</Text><Textstyle={styles.instructions}>          Press Cmd+R to reload,{'\n'}          Cmd+Control+Z for dev menu</Text></View>);},_resetExperiment(){this.refs.welcomeExperiment.reset();}});varstyles=StyleSheet.create({container:{flex:1,justifyContent:'center',alignItems:'center',backgroundColor:'#F5FCFF',},welcome:{fontSize:20,textAlign:'center',margin:10,},instructions:{textAlign:'center',color:'#333333',marginBottom:5,},});AppRegistry.registerComponent('rnabtest',()=>rnabtest);

<Experiment> Properties

name

The name of your experiment, for example"welcome-message".

choose

Example callback signature:function(variants)Must return an instance ofVariant

A function which should use a randomization algorithm to pick one of your variants. Defaults to a random selection usingMath.random()

onChoice

Example callback signature:function(experimentName, variantName)

Called when aVariant has been chosen for yourExperiment.

onRawChoice

Example callback signature:function(experiment, variant)

Same asonChoice, but the objects passed are React component instances.

<Experiment> methods

You can access component methods by adding aref (ie.ref="welcomeExperiment") prop to your<Experiment> element, then you can usethis.refs.welcomeExperiment.reset(), etc. inside your component.

reset()

Resets the experiment. The next time the experiment is rendered, a new variant may be chosen.

getActiveVariant()

Returns the currently displayedVariant.

getVariant(variantName)

Returns the instance of the specifiedVariant name.

<Variant> Properties

name

The name of your variant, for example"western".

Subviews

Only theVariant tag element exist within theExperiment element.Variant tags can contain only oneroot element.

About

A component for rendering A/B tests in React Native

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp