Installations
npm install ab-test-selector
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=14.0.0
Node Version
14.21.2
NPM Version
6.14.17
Score
67.5
Supply Chain
97.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
tcollinsworth
Download Statistics
Total Downloads
3,305
Last Day
1
Last Week
15
Last Month
44
Last Year
326
GitHub Statistics
3 Stars
24 Commits
1 Forks
2 Watching
3 Branches
1 Contributors
Bundle Size
572.00 B
Minified
309.00 B
Minified + Gzipped
Package Meta Information
Latest Version
3.0.4
Package Id
ab-test-selector@3.0.4
Unpacked Size
12.07 kB
Size
4.34 kB
File Count
5
NPM Version
6.14.17
Node Version
14.21.2
Publised On
08 Jan 2023
Total Downloads
Cumulative downloads
Total Downloads
3,305
Last day
0%
1
Compared to previous day
Last week
25%
15
Compared to previous week
Last month
33.3%
44
Compared to previous month
Last year
-57%
326
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
AB test selector
This library consistently assigns ids/keys to A or B test pool group for A/B testing. An id may be any valid number or string, i.e., userId, orgId/tenantId, etc.
This library is simple to integrate and fast. It has very low latency and prevents users from randomly changing test pool groups which would pollute test results.
Tenant or org ids can be utilized for A/B selection in multi-tenant systems. This is useful where testing a subset of tenants is desired. Groups are also useful for monotonically increasing the size of population under test. Best practice is to initially start with a small subset to validate no significant negative effects and then increasing to full population.
This implementation does not need any remote request to select A/B. Remote requests will increase latency to end users. Remote requests might (will occasionally) fail. When failure, the user might (will 50% of the time) change groups which pollutes/skews the test results unpredictably.
By convention and for simplicity/consistency, the A group should be the existing behavior, B should be the new behavior (treatment). Not required though.
By default, all users are included in the AB test. The assignment algorithm is (hash(id) % 2 ? 'B' : 'A').
"Data Trumps Intuition" "significant learning and return-on-investment (ROI) are seen when development teams listen to their customers, not to the Highest Paid Person’s Opinion (HiPPO)", Practical Guide to Controlled Experiments on the Web: Listen to Your Customers not to the HiPPO by Ronny Kohavi, PhD
Requirements
Node 10+ ECMAScript module
ECMAScript module
This library uses ECMAScript module features. It must be used with one of the following:
-
package.json with
type: module
-
or loaded from a javascript file with .mjs extension
-
or loaded after an esm shim, i.e., esm or esm-wallaby which supports optional-chaining (elvis)
Performance
On 2019 HP x360 Spectre with Ubuntu 18.04.3 64 bit
Intel® Core™ i7-8565U CPU @ 1.80GHz × 8
~275K AB selections / second
~3.6 microseconds each selection
Getting started
1npm i -S ab-test-selector
Usage
Configuration Options
Configuration options with defaults that can be passed to the constructor.
1{ 2 enabled: true, // enable/disable A/B selection, false always returns A 3 idBonly: [], // ALL or specific ids/keys to always get B 4 groupBonly: [], // ALL or specific group ids/keys to always get B 5 idExcludes: [], // specific ids/keys to exclude from A/B, get A only 6 idIncludes: ['ALL'], // ALL or specific ids/keys to include in A/B 7 groupExcludes: [], // specific group ids/keys to exclude from A/B, get A only 8 groupIncludes: ['ALL'], // ALL or specific groups ids/keys to include in A/B 9}
Ideally, expose/integrate configuration via environment variables following 12 Factor App. Alternatively expose via central Service Discovery/configuration (etcd, consul, zookeeper, RDBMS, etc.) or REST endpoints. This will allow dynamically changing configuring while the system is running.
If statistical significance is achieved and B wins. So all users will then see B, set the idBonly or groupBonly to ['ALL']. This will route all users to the B treatment until the implementation is updated to remove the A/B test selector.
Partial configuration will use defaults for unspecified properties.
There are getEnabled() and setEnabled(boolean) methods.
The getConfiguration() and setConfiguration(config) methods allow setting full or partial configuration dynamically while executing.
Listed above in order of evaluation precedence, first definitive resolution is returned.
The precedence is hard-coded, changing the order here does not change the precedence.
The arrays are converted to Sets internally for performance in case large lists are needed.
AB on user ID, for all users
1import AbTestSelector from 'ab-test-selector' 2 3const ab = new AbTestSelector() 4 5if (ab.getAB(userId) == 'B') { 6 computeOrShowTreatmentB() // change this to call your application code 7} else { 8 computeOrShowTreatmentA() // change this to call your application code 9}
Switch to B for all users if/when B wins
Dynamically switch all users to B treatment
1ab.setConfiguration({ 2 idBonly: ['ALL'], // either this line or the other line 3 groupBonly: ['ALL'], // either this line or the other line 4})
AB only some user IDs, others all get A
1import AbTestSelector from 'ab-test-selector' 2 3const ab = new AbTestSelector({ 4 idIncludes: [7,12] 5}) 6 7if (ab.getAB(userId) == 'B') { 8 computeOrShowTreatmentB() // change this to call your application code 9} else { 10 computeOrShowTreatmentA() // change this to call your application code 11}
AB on user ID, exclude some groups/orgs/etc. which all get A
1import AbTestSelector from 'ab-test-selector' 2 3const ab = new AbTestSelector({ 4 groupExcludes: [3,5] // exclude some group or org IDs, can be any scalar, like string or UUID, etc. 5}) 6 7if (ab.getAB(userId, groupId) == 'B') { 8 computeOrShowTreatmentB() // change this to call your application code 9} else { 10 computeOrShowTreatmentA() // change this to call your application code 11}
AB on user ID, include only some groups/orgs/etc., others all get A
1import AbTestSelector from 'ab-test-selector' 2 3const ab = new AbTestSelector({ 4 groupIncludes: [3,5] // exclude some group or org IDs, can be any scalar, like string or UUID, etc. 5}) 6 7if (ab.getAB(userId, groupId) == 'B') { 8 computeOrShowTreatmentB() // change this to call your application code 9} else { 10 computeOrShowTreatmentA() // change this to call your application code 11}
More information
See the tests and implementation files.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE.txt:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0
Reason
7 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Reason
Found 0/16 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Score
2.1
/10
Last Scanned on 2025-01-06
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More