Miss any of our Open RFC calls?Watch the recordings here! »

@godaddy/split-data-loader

1.1.1 • Public • Published

Join Slack

split-javascript-data-loader

Loads serialized rule/segment data from Split.io into the browser local storage.

Installation

Install via npm:

$ npm i @godaddy/split-data-loader --save

Usage

Use this package if you are using Split.io for experimentation on a webpage and want to take advantage of browser caching with localStorage.

Please note that this package is intended to be used in tandem with a split data serializer to create the serializedData parameter properly. An example of such serializer is split-node-serializer.

import loadDataIntoLocalStorage from '@godaddy/split-data-loader'
 
loadDataIntoLocalStorage({
  serializedData: {
    segmentsData: {
      "segment_1": "{ name: 'segment_1', added: ['test-visitor-1', 'test-visitor-2', 'test-shopper-1'] }",
      "segment_2": "{ name: 'segment_2', added: ['test-visitor-1', 'test-visitor-3', 'test-shopper-2'] }"
    },
    since: '100',
    splitsData: {
      "experiment_1": "{ name: 'experiment_1', status: 'foo' }",
      "experiment_2": "{ name: 'experiment_2', status: 'bar' }"
    },
    usingSegmentsCount: 2
  },
  userId: 'test-visitor-1'
})
// console.log(window.localStorage)
// {
//   "SPLITIO.splits.till": "100",
//   "SPLITIO.split.experiment_1": "{ name: 'experiment_1', status: 'foo' }",
//   "SPLITIO.split.experiment_2": "{ name: 'experiment_2', status: 'bar' }",
//   "SPLITIO.splits.usingSegments": "2",
//   "test-visitor-1.SPLITIO.segment.segment_1": "1",
//   "test-visitor-1.SPLITIO.segment.segment_2": "1"
// }

Function

loadDataIntoLocalStorage

You can use this function to store the following in browser localStorage:

  • Freshness of your data
  • Serialized split data
  • Count of splits using segments
  • Indicators for which segments a userId is a part of

The following option properties are available:

Property Description
serializedData.segmentsData An object of segment data you want to use to cache which segments a given userId is part of. (required)
serializedData.since The freshness of the incoming serialized data. If this is less than or equal to the since value in localStorage, nothing will happen. (required)
serializedData.splitsData An object of serialized split data you want to cache. (required)
serializedData.usingSegmentsCount The count of splits using segments. (required)
userId The user id that is a part of an experiment. Either a hashed shopperId or visitorGuid. (required)
storagePrefix An optional parameter that represents the storage.prefix in the SplitIO configuration of the SplitIO factory you are using.

Testing

Run the linter:

$ npm run lint

Run unit tests:

$ npm test

Generate a coverage report:

$ npm run coverage

License

MIT

Keywords

none

Install

npm i @godaddy/split-data-loader

DownloadsWeekly Downloads

5

Version

1.1.1

License

MIT

Unpacked Size

19.9 kB

Total Files

12

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar