@visionect/frontend-experiments
v0.3.0
Published
Experiment utility
Downloads
3
Keywords
Readme
Frontend Experiments
Install
yarn add @visionect/frontend-experiments
or
npm install --save @visionect/frontend-experiments
Usage
import Experiments from "@visionect/frontend-experiments"
const expConfig = [
{
name: 'EXP-01',
variants: [
{
name: 'simple_cta',
payload: 'Sign up',
},
{
name: 'alter_cta',
payload: 'Start free trial',
}
]
}
]
const ExpProvider = new Experiments(expConfig)
// Broadcast values to analytics
const variant = ExpProvider.getVariant('EXP-01')
// Set custom dimension 1 to 'simple_cta' or 'alter_cta'
window.ga && window.ga('set', 'cd1', variant.name)
// Button text is Sign up / Button text is Start free trial
console.log('Button text is', variant.payload)
// Fetch payload from a child component
const exp01CTA = ExpProvider.getPayload('EXP-01')
const Button = ({ onClick }) => (
<button onClick={onClick}>
{exp01CTA}
</button>
)
(c) 2019 Visionect