npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

banana-split

v0.10.0

Published

Split testing for Node.js and MongoDB

Downloads

96

Readme

Banana Split - early alpha version

Build Status

A small split testing (also called A/B testing and multivariate testing) library for Node.js using MongoDB for storage.

What it does

  • Stores all data in MongoDB, including experiments, participants, and events
  • Allocates a random variation for each participant in an experiment
  • Tracks conversion events generated by participants. e.g. "signup", "upgraded", "clicked-button"
  • Calculates the conversion rates for each variation in a given (experiment, event) pair

What it doesn't do

  • No UI - there's no admin panel or dashboard of any kind
  • No HTTP server - it doesn't have a HTTP API (although it would be easy to write one if you wish)

Getting Started

Add banana-split to your node.js project:

npm install banana-split --save

In your node.js code, initialize the module as follows:

// set up a mongodb connection with mongoose
var mongoose = require('mongoose');
var db = mongoose.createConnection("mongodb://localhost:27017/myappdata");

var bananaSplit = require('banana-split')({
  db: db, 
  mongoose: mongoose
});

Add an experiment...

bananaSplit.initExperiment({
  name: 'buttonColor',
  variations: ['red', 'green']
});

Let's participate a user with ID 'user-1' and IP address '127.0.0.1'...

bananaSplit.participate({
  experiment: 'button-color',
  user: 'user-1',
  ip: '127.0.0.1'
}, function (err, variation) {
  // variation will now be either 'red' or 'green'
})

Track a couple of events by this user...

bananaSplit.trackEvent({
  user: 'user-1',
  ip: '127.0.0.1',
  name: 'signup'
})
bananaSplit.trackEvent({
  user: 'user-1',
  ip: '127.0.0.1',
  name: 'click-button'
})

Later, after many users have participated and generated events, calculate the results with...

bananaSplit.getResults({
  experiment: 'buttonColor',
  event: 'name'
}, function (err, result) {
  // put code to deal with result here
});

Here's an example of the kind of the result from getResult():

TODO: example

To interpret these confidence intervals, there's a 95% chance that the true conversionRate lies within the range:

conversionRate ± confidenceInterval

i.e. we have a 95% confidence that conversion rate for the "red" variation is:

51.5% ± 3.0%

Anonymous and signed in users

Banana-split doesn't distinguish between anonynous and signed in users. In case it helps, this is the method I'm using to handle anonymous users:

1. New anonymous visitor hits landing page

  • Generate a user ID for the anonymous visitor and place it in session storage.
  • Participate in any appropriate experiments on this landing page using this user ID.
  • Render the page based on the variations.

2. Anonymous visitor signs up for new account

  • Use the generated user ID as their new permenant user ID

3. Anonymous visitor signs in to an existing account

  • The temporary user ID is no longer interesting, and to avoid adding noise to the data, I opt-out this temporary user using the following function:
bananaSplit.optOut({
  user: '54dded1e5287fcd4a5717c04'
})

More about getResult()

Filtering: only one participant from each IP address

The getResult() function filters out all but the first user from a given IP address. This is to:

  1. Eliminate a lot of new 'users' who were generated when an existing user signs out.
  2. Prevent many requests from one IP address from adding noise. e.g. search engine bots or other web-scrapers will only be counted once each
  3. Prevent many users from one IP address skewing the results. e.g. if many users joined from a single IP address there's a good chance they all belong to the same familiy or organization and may share a certain bias which could skew the results.

The data for all these users is stored in MongoDB so changing this behavior is possible after gathering the data. The behavior above is based on my intuition and needs and if you'd like it to be different please let me know and I can add an option.

WARNING: Scaling for large websites

As the number of participants and events increases, calls to getResult() will become more expensive. It would make sense to calculate this incrementally instead of re-calculating it from scratch each time.

State of development

I'm using this in production for Readlang but it's still immature. If you decide to use it I'd love to hear from you, please report issues and suggestions for improvements on the issues page.