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

@kiwicom/splitster

v0.0.57

Published

Javascript AB testing tool

Downloads

1,575

Readme

Splitster

Javascript AB testing tool

Configuration

import splitsterInit from "splitster"
splitsterInit(config)

Where config is an object with following structure:

const config = {
  tests,
  userGroups,
  tracks,
  options,
}
export default config

tests

Object of key value pairs representing running tests.

Key: string id of test

Value: test configuration

// Your tests specified by id
const tests = {
  // Test with id test_1
  test_1: {

    // Short description - optional
    description: "Check if user likes more red, blue or green button",

    // Groups which user must satisfy - optional
    userGroups: ["enUsers"],

    // Overall usage of test in % - optional - if not specified 100 is used
    usage: 100,

    // Array of tracks to use when test is ran - optional
    runTrack: [],

    // Array of tracks to use when test is being first time applied in code - optional
    useTrack: [],

    // Array of tracks to use when test is successful
    endTrack: [],

    // Test is disabled, always return default variant
    disabled: false,

    // Default variant id
    defaultVariant: "RED",

    // Variants of the test specified by id.
    variants: {

      // Variant with id RED
      RED: {
        // If test is not ran, variant with specified default value is always returned

        // Actual value of variant. Will be return by calling splitser.get(test_id).value
        value: "RED",

        // Ratio of probability distribution against other variants
        // ratio 1-1 (also 50-50) means 50% probability
        ratio: 3,
      },
      BLUE: {
        value: "BLUE",
        ratio: 4,
      },
      // Shorthand - value is same as ID
      GREEN: 2,
    },
  },
}

tracks

Track may be string ID of object specified in general tracks section, or inline function taking result of test:

[
  GENERAL_TRACK_ID,
  (res) => {},
]

runTrack

tracks used when experiment is ran - this happens only one per test life

splitster.run(test_id) // Runs one experiment
// OR
splitster.runAll() // Runs all experiments

useTrack

tracks used when experiment value is required. Runs only once. Useful to make sure user has really seen experiment in action

const variant = splitster.get(test_id) //useTracks calling
if (variant.value === 1) {
  // Do stuff
} else if (variant.value === 2) {
  // Do other stuff
}

endTrack

final tracks when test is successful. May be called multiple times.

document.getElementById("button").addEventListener("click", () => {
  splitster.track(test_id) //endTracks calling
})

userGroups

Defines groups which user must satisfies if test can be started.

import splitsterInit from "splitster"
splitsterInit(config, user)

Object of key value pairs

const userGroups = {
  enUsers: [
    {"language": ["en", "hi"]}
  ],
  customUsers: [
    (user) => user.isValid(),
  ]
}

one group is an array of rules which user object must satisfies.

Rule can be object: defining structure of user object

or function which takes user object and if returns true, rule passed

tracks

Object of tracks specified by id

Track is a function taking test object and doing developer specified tasks. Useful for logging, sending results etc.

tracks = {
  CONSOLE_TRACK: (test) => { console.log(test) },
}

options

Other options to set

separateTest: if true, only one test is used at time. Test is chosen randomly. Useful when you don't want to pollute your results with too many tests running at the same time.

cookies

disabled: if true, tests will not be saved to cookies. Initialization won't get result from cookies but always run.

expiration: number of days cookies should last.

name: prefix of cookies set in browser - default splitster {name_test_id}