@felipelealdefaria/experiments-service v1.1.1
Experiments Service
Experiments service for creating A/B tests using lib sixpack-js.
Requirements
Clone this repo sixpack-docker and run:
docker-compose upAPI URI: http://127.0.0.1:5000/
SIXPACK DASH: http://127.0.0.1:5001/Installation
yarn add @felipelealdefaria/experiments-service
# or
npm i @felipelealdefaria/experiments-serviceUsage
import experiment from '@felipelealdefaria/experiments-service'1) Initialize:
This is required before any other methods can be called.
await experiment.init(params: InitParams): Promise<InitResponse>InitParams:
- baseUrl: string
- timeout?: number (default: 8000)InitResponse:
- session: unknown
- error?: boolean
- success?: boolean
- message?: string2) Experiment Participate:
To start an experiment (test a/b).
await experiment.participate(params: ParticipateParams) => Promise<ParticipateResponse>ParticipateParams
- session: unknown
- traffic?: number (default: 1) // means 50% for each variable
- variationsName: string[]
- experimentName: stringParticipateResponse
- alternativeName?: string | null
- experimentName?: string | null
- error?: boolean
- success?: boolean
- message?: string3) Experiment Convert:
To convert an experiment KPI.
await convert(params: ConvertParams) => Promise<ConvertResponse>ConvertParams
- kpi?: string
- session: unknown
- experimentName: stringConvertResponse
- kpi?: string
- experimentName?: string
- alternativeName?: string
- error?: boolean
- success?: boolean
- message?: string4) A/B Test with React.Js:
return (
<>
{ res?.alternativeName === 'variant_option'} ? <ComponentA /> : <ComponentB /> }
</>
)OBS To force the variation, insert in your browser cookies:
key: force-${experimentName}
value: ${variation_option}Possible error for those using webpack
The dependency of the project, sixpack-client has incompatibility with some versions of the webpack. The common error in this case may be linked to not being able to resolve the http and buffer dependencies.
To fix it, in your webpack.config.js file:
resolve: {
fallback: {
http: require.resolve('stream-http'),
buffer: require.resolve('buffer/')
}
}Service's Architecture
Service created using the principles of Clean Architecture with the intention of facilitating maintenance and a possible exchange of lib used to perform A/B tests.
