• Stars
    star
    312
  • Rank 134,133 (Top 3 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple, progressive, client/server AB testing library πŸ“š

A progressive, client/server AB testing library.

CircleCI codecov Greenkeeper badge npm bower

Study is an AB testing library designed to be clear, minimal, and flexible. It works in both the server and browser with the use of driver-based persistence layers.

You can download the compiled javascript directly here


Features

  • Powerful, clear API
  • Many variations. ABCD testing
  • Intelligent weighted bucketing
  • Browser & Server support
  • Storage Drivers: localStorage, cookies, memory, or build your own
  • Well documented, tested, and proven in high production environments
  • Lightweight, weighing in at ~ 3.8kb.
  • Not tested on animals

Installing

# Via NPM
npm i studyjs --save

# Via Bower
bower i studyjs --save

# Via Yarn
yarn add studyjs

Developing

npm install # Install dependencies
npm build # Build the babel'd version
npm lint # Run linting
npm test # Run tests

Usage

<script src="study.js"></script>
<script>

  // Set up our test API
  const test = new Study({
    store: Study.stores.local
  });

  // Define a test
  test.define({
    name: 'new-homepage',
    buckets: {
      control: { weight: 0.6 },
      versionA: { weight: 0.2 },
      versionB: { weight: 0.2 },
    }
  });

  // Bucket the user
  test.assign();

  // Fetch assignments at a later point
  const info = test.assignments();
</script>

API

Study(config)

const study = new Study({
  debug: true,
  store: Study.stores.local
});

This creates a new test API used to defined tests, assign buckets, and retrieve information.

Returns: Object

Name Type Description Default
debug Boolean Set to true to enable logging of additional information false
store Object An object with get/set properties that will accept information to help persist and retrieve tests Study.stores.local

study.define(testData)

// Create your test API
const study = new Study();

// Define a test
study.define({
  name: 'MyTestName',
  buckets: {
    variantA: { weight: 0.5 },
    variantB: { weight: 0.5 },
  },
});

This function defines the tests to be assigned to used during bucket assignment. This function accepts an object with two keys, name and buckets. Alternatively, you may pass an array of similar objects to define multiple tests at once.

The name value is the name of your test. The keys within bucket are your bucket names. Each bucket value is an object containing an object with an optional key weight that defaults to 1.

The percent chance a bucket is chosen for any given user is determined by the buckets weight divided by the total amount of all weights provided for an individual test. If you have three buckets with a weight of 2, 2/6 == 0.33 which means each bucket has a weight of 33%. There is no max for the total weights allowed.

Returns: null

Name Type Description Default
data Object/Array An object/array of objects containing test and bucket information null

study.assign(testName, bucketName)

const study = new Study();
study.define({
  name: 'new-homepage',
  buckets: {
    variantA: { weight: 0.5 },
    variantB: { weight: 0.5 },
  }
});

// Assign buckets from all tests to the user...
study.assign();

// or assign bucket from the specified test...
study.assign('new-homepage');

// or specify the bucket from the specified test...
study.assign('new-homepage', 'variantB');

// or remove the bucketing assignment from the specified test.
study.assign('new-homepage', null);

Calling the assign method will assign a bucket for the provided tests to a user and persist them to the store. If a user has already been bucketed, they will not be rebucketed unless a bucketName is explicitly provided.

If no arguments are provided, all tests will have a bucket assigned to the user. If the first argument provided is a test name, it will attempt to assign a bucket for that test to a user. If a bucketValue is provided, it will set that user to the specified bucket. If the bucketValue is null, it will remove that users assignment to the bucket.

Returns: null

Name Type Description Default
testName (optional) String The name of the test to assign a bucket to null
bucketName (optional) String The name of the bucket to assign to a user null

study.definitions()

const study = new Study();
study.define({
  name: 'new-homepage',
  buckets: {
    variantA: { weight: 0.5 },
    variantB: { weight: 0.5 },
  }
});

// Retrieve all of the provided tests
const tests = study.definitions();

This provides the user with all of the tests available.

The returned information will be an array if multiple tests were defined, otherwise, it will be an object of the single test defined. The object will mirror exactly what was provided in the define method.

Returns: Object|Array


study.assignments()

const study = new Study();
study.define({
  name: 'new-homepage',
  buckets: {
    variantA: { weight: 1 },
  }
});

// Capture assignments
study.assign();

// Retrieve all of the bucket assignments for the user
const buckets = study.assignments();
assert.strictEqual(buckets['new-homepage'], 'variantA');

This provides the user with all of the bucket assignments for the current user.

The returned information will be an object whose keys will be test names and values will be the current bucket assigned to the user.

// Example return
{
  'new-homepage': 'variantA',
  'some-test': 'some-bucket',
}

Returns: Object|Array


study.extendAssignments

Extending assignments can be a useful way to augment your Study implementation with third party software.

const study = new Study();

// Create a function that will modify assignments before you call `assignments`
study.extendAssignments =
  (assignments) => Object.assign(assignments, { foo: 'bar' })

// Retrieve all of the bucket assignments for the user
const buckets = study.assignments();
assert.strictEqual(buckets['foo'], 'bar');

A more practical example could be to implement with a third party AB testing platform like Optimizely (This uses pseudo code for brevity)

study.extendAssignments = (assignments) => {
  if (window.optimizely)
    for (const experiment in optimizely.experiments())
      assignments[experiment.name] = experiment.bucket

  return assignments
}

Returns: Object


Guide/FAQ

CSS Driven Tests

Tests logic may be potentially powered on solely CSS. Upon calling assign, if the script is running in the browser, a class per test will be added to the body tag with the test name and bucket in BEM syntax.

<body class="new-homepage--variantA"> <!-- Could be new-homepage--variantB -->
.new-homepage--variantA {
  /* Write custom styles for the new homepage test */
}

Storing metadata associated with tests

Each bucket provided may have additional metadata associated with it, and may have its value retrieved by retrieving the assignments and definitions.

const study = new Study();
study.define({
  name: 'new-homepage',
  buckets: {
    variantA: { weight: 1, foo: 'bar' },
  }
});

study.assign();

const defs = study.definitions();
const buckets = study.assignments();
const bucket = buckets['new-homepage'];
const bar = defs.buckets[bucket].foo; // "bar"

License

MIT Licensing

Copyright (c) 2015 - 2018 Dollar Shave Club

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

stickybits

Stickybits is a lightweight alternative to `position: sticky` polyfills 🍬
JavaScript
2,190
star
2

shave

πŸ’ˆ Shave is a 0 dep JS plugin that truncates text to fit within an element based on a set max-height ✁
JavaScript
2,109
star
3

postmate

πŸ“­ A powerful, simple, promise-based postMessage library.
JavaScript
1,860
star
4

reframe.js

πŸ–Ό Reframe unresponsive elements responsively.
JavaScript
1,599
star
5

scrolldir

0 dependency JS plugin to leverage scroll direction with CSS ⬆⬇ πŸ”ŒπŸ’‰
JavaScript
662
star
6

cloudworker

Run Cloudflare Worker scripts locally
JavaScript
516
star
7

es-check

Checks the version of ES in JavaScript files with simple shell commands πŸ†
JavaScript
460
star
8

ImageButter

Makes dealing with images buttery smooth.
C
394
star
9

furan

Scale out Docker builds
Go
344
star
10

polymerase

A tool for populating templates with environment variables and Vault values
Go
84
star
11

react-passage

Link and Redirect to routes safely in your react applications πŸŒ„
JavaScript
58
star
12

package-diff

Diffs the packages used between two node_modules folders
JavaScript
57
star
13

ex_cluster

Clustered Elixir OTP application on Kubernetes with Horde and LibCluster
Elixir
53
star
14

ember-responds-to

Simple mixins for browser event handling.
JavaScript
41
star
15

fastboot-docker

[DEPRECATED] Ember FastBoot App Server in a box.
JavaScript
34
star
16

e2e

Make End-to-End Testing Great For Once
JavaScript
32
star
17

line

An easy to use golang package for stylizing terminal output
Go
27
star
18

ember-route-layers

Wire up your cancel buttons in easy mode.
JavaScript
26
star
19

ember-uni-form

Powerful forms without the confusion.
JavaScript
23
star
20

dynamo-drift

Go
23
star
21

terraform-provider-nrs

A Terraform provider for New Relic Synthetics
Go
22
star
22

monitor

A remote uptime monitoring framework for running monitors as a CRON job
JavaScript
21
star
23

vault-dev-docker

Vault docker image for local development
Shell
16
star
24

s3-uploader

Concurrent streaming upload to Amazon S3
Go
16
star
25

guardian

Go
13
star
26

ember-cli-anybar

A non-intrusive build notification system built atop AnyBar.
JavaScript
12
star
27

golang-protobuf-base-docker

Shell
9
star
28

psst

A secret sharing tool
Go
9
star
29

talcum

Talcum allows members of a distributed system to auto-configure themselves πŸ‘₯
Go
9
star
30

runtype

Runtype converts Typescript type aliases, interfaces, and enums to Javascript that can be used during runtime
JavaScript
9
star
31

vaultenvporter-go

A tool for turning a set of Vault secrets into environment variables
Go
8
star
32

harmless-changes

Ignore unnecessary build steps if changes are harmless to make builds faster 🏎 πŸ’¨
Shell
7
star
33

node-auto-repair-operator

A Kubernetes operator that can repair problematic nodes (under development)
Go
6
star
34

eslint-config-dollarshaveclub

Base eslint configs for Dollar Shave Club.
JavaScript
5
star
35

dependents

Shows package dependency versions in specified repositories
JavaScript
5
star
36

new-relic-synthetics-go

A New Relic Synthetics API client for Go
Go
5
star
37

pvc

Applications secrets access library
Go
4
star
38

Swift-WebP

Easy WebP usage in your iOS app!
C
4
star
39

ember-link-after-build

Symlink a folder in lieu of copying files for faster build times
JavaScript
4
star
40

fastboot-cluster-node-cache

A FastBoot app server cache built atop cluster-node-cache
JavaScript
3
star
41

jobmanager

Go
3
star
42

crudite

Go
3
star
43

go-productionize

A set of libraries that will help Go services be more production ready
Go
3
star
44

thermite

Removes old Amazon Elastic Container Registry images that are not deployed in a Kubernetes cluster
Go
2
star
45

go-lib

Go
2
star
46

sysctl-write-docker

Go
2
star
47

ember-shave

A simple wrapper over DSC's super fast and simple text truncation library called shave.
JavaScript
2
star
48

redis-resp

Go
2
star
49

ember-qualtrics

Ember Qualtrics Site Intercept addon.
JavaScript
1
star
50

eslint-plugin-dollarshaveclub

Linting code to shave the world.
JavaScript
1
star
51

ember-preapp-adapter

Request a payload before your Ember app has loaded.
JavaScript
1
star
52

go-for-newbs

Sample applications for people learning Go
Go
1
star
53

vault-shared-users

Vault Shared Users for securely allowing access to robot accounts across the organization
Go
1
star