🍞 Breadknife.js 🍞
Dead Simple A/B Testing so you can focus on getting that bread 🍞.
npm install breadknife
yarn add breadknife
Setting up a test
First import the library.
import Breadknife from 'breadknife'
Second you need a config file to list out the A/B tests you are using, the format is an array of objects, this can be anywhere in your code or even come from a database if need be.
const exampleConfig =id: 'EXAMPLE_TEST'split:TEST: 05CONTROL: 05
Once your config is set you have to initialize the tests.
Then you can check the slice of a test anywhere else in your code.
this will return a string matching one of the constants in
you can use this to conditionally render code:
let textifBreadknife === BreadknifeTESTtext = "I'm test text!"elsetext = "I'm control text!"
Disabling a test
Breadknife stores all tests on the clients local storage so that slices can persist between sessions, if you need to temporarily disable a test without removing it you can add
disabled: true to the config for that test. Disabled tests always return
const exampleConfig =id: 'EXAMPLE_TEST'split:TEST: 05CONTROL: 05disabled: true
Removing a test
If a test is not longer necessary it can simply be removed from the config and it wont be saved on the next
Breadknife.init() call, if a test that does not exist is provided to the
Breadknife.getSlice() function, it will always return
id of a test must be a unique string, duplicate ID's in the same config result in an error.
The split object
The split object must be a an object with at least a
you can have up to a 4 way split test by adding a
TEST_C to the object.
Finally, all of the values in the split object must be floats that when added together equal between
1 (not just 1 because 3 way tests can sometimes result in imperfect math)
Three way test:
exampleConfig =id: 'EXAMPLE_TEST'split:CONTROL: 033TEST: 033TEST_B: 033
Four way test:
exampleConfig =id: 'EXAMPLE_TEST'split:CONTROL: 025TEST: 025TEST_B: 025TEST_C: 025
Constants for easier test definition
Breadknife comes with 3 predefined constants
FOUR_WAY for when you just want a dead simple split for your tests.
const exampleConfig =id: 'EXAMPLE_TEST'split: HALF_AND_HALFid: 'EXAMPLE_3_WAY'split: THREE_WAYid: 'EXAMPLE_4_WAY'split: FOUR_WAY
Forcing a test version
If you need to force a test into a certain slice you can use the
Breadknife.forceTestSlice(id, state) function.
Listing all tests
If you need to return a list of all tests with their slices you can use