Created
September 22, 2020 00:25
-
-
Save max8hine/b03b3e195224b84d874ece92d1b84300 to your computer and use it in GitHub Desktop.
AB testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const variants = { | |
exp1: "base", | |
exp2: "variant2", | |
exp3: "variant3", | |
}; | |
const experimentSettings = { | |
activate(exp_name, unique_identifier) { | |
// Api call to the server | |
return variants[exp_name] || 'base'; | |
}, | |
tract(event_name, unique_identifier) { | |
// API call to the server | |
return true; | |
} | |
} | |
const ExperimentContext = React.createContext(experimentSettings); | |
class Main extends React.Component { | |
render() { | |
return ( | |
<ExperimentContext.Provider> | |
<App /> | |
</ExperimentContext.Provider> | |
); | |
} | |
} | |
class AnywhereYouWantToApply extends React.Component { | |
render() { | |
return ( | |
<ExperimentContext.Consumer> | |
{({ activate }) => { | |
const decision = activate("exp_name", UUID); | |
if (decision === "variant") return <Variant />; | |
return <Base />; | |
}} | |
</ExperimentContext.Consumer> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment