Norway Porridge Makers

    @wework/we-experiment-js

    1.2.0 • Public • Published

    WeExperiment

    A thin abstraction layer for A/B testing.

    Currently built on top of Split.io's JavaScript SDK.

    This package is complemented by we-experiment-react.

    Installation

    npm install --save @wework/we-experiment-js
    

    Usage

    import weExperiment from 'we-experiment';
    
    const experiments = weExperiment('USER_ID', 'SPLIT_API_KEY', {
      userAttributes: {
        // Optional user attributes
      }
    });
    
    experiments.getExperiment('foo')
      .then(experiment => {
        // experiment is a string equal to the user's experiment variant, or null.
      })
      .catch(error => {
        // we-experiment handles SDK init issues transparently, but in the unlikely event another error arises, you should catch it here
      });
    
    experiments.getExperiments(['foo', 'bar'])
      .then(experiments => {
        /*
          experiments === {
                            foo: '...',
                            bar: '...'
                          }
         */
      });

    Additional attributes

    When getting experiments, it is possible to add additional attributes to the userAttributes supplied at initialization, or override existing attributes.

    const experiments = weExperiment('USER_ID', 'SPLIT_API_KEY', {
      userAttributes: {
        foo: 'foo' // initial attributes
      }
    });
    
    experiments.getExperiment('bar', { bar: 'bar' }) // passed attributes are now { foo: 'foo', bar: 'bar' }
      .then(experiment => {})
      .catch(error => {});

    Overrides

    It is possible to override experiments by initializing the library like so:

    weExperiment('USER_ID', 'SPLIT_API_KEY', {
      experimentOverrides: {
        foo: 'variant_1',
        bar: 'variant_2'
      }
    });

    Additional Split.io options

    It's possible to pass additional options to the Split.io library in the following way:

    weExperiment('USER_ID', {
      // ...
      extraOptions: {
        // Split.io factory options here
      }
    });

    For more information on the possible options, see: http://docs.split.io/docs/javascript-sdk-overview#section-advanced-configuration-of-the-sdk

    Note that core.authorizationKey and core.key are already passed as apiKey and userId respectively.
    Additionally, features are passed in as experimentOverrides.

    Publish

    npm run build
    npm version [patch, minor, major]
    npm publish
    

    Keywords

    none

    Install

    npm i @wework/we-experiment-js

    DownloadsWeekly Downloads

    49

    Version

    1.2.0

    License

    UNLICENSED

    Unpacked Size

    23.5 kB

    Total Files

    11

    Last publish

    Collaborators

    • wework-dev
    • volodymyr.pratsin
    • wework-growth
    • mryave
    • narcisacodreanu
    • telkowework
    • rbuenviaje
    • leoduquesnel
    • liormb
    • aishwaryap
    • kenyav
    • nicole-wework
    • acartmell
    • smartang
    • minareth
    • kh0st
    • whittier
    • kyokeefesally
    • eburgoswework
    • seansmith_wework
    • lekan.nicholson
    • mossolinski
    • befron
    • kostiantyn.yaremenko
    • ubin.malla