mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-14 18:05:01 +00:00
7617174d40
Provides a class that initiates AB-test bucketing and registers as a MF module. Activates the reading depth test for users who are bucketed in either buckets "A" or "B". Does not add event-logging or visual style changes for page issues AB test. Bug: T193584 Change-Id: If8504a35059c6d1b056cef063a595b1c2ffd351a
79 lines
1.7 KiB
JavaScript
79 lines
1.7 KiB
JavaScript
/*
|
|
* Bucketing wrapper for creating AB-tests.
|
|
*
|
|
* Given a test name, sampling rate, and session ID, provides a class
|
|
* that buckets users into predefined bucket ("control", "A", "B") and
|
|
* starts an AB-test.
|
|
*/
|
|
|
|
( function ( mw, M, mwExperiments ) {
|
|
|
|
/**
|
|
* Buckets users based on params and exposes an `isEnabled` and `getBucket` method.
|
|
*
|
|
* @param {string} testName name of the AB-test.
|
|
* @param {number} samplingRate sampling rate for the AB-test.
|
|
* @param {number} sessionId session ID for user bucketing.
|
|
* @constructor
|
|
*/
|
|
function AB( testName, samplingRate, sessionId ) {
|
|
|
|
var CONTROL_BUCKET = 'control',
|
|
test = {
|
|
name: testName,
|
|
enabled: !!samplingRate,
|
|
buckets: {
|
|
control: 1 - samplingRate,
|
|
A: samplingRate / 2,
|
|
B: samplingRate / 2
|
|
}
|
|
};
|
|
/**
|
|
* Starts the AB-test and enters the user into the Reading Depth test.
|
|
*/
|
|
function startABTest() {
|
|
// See: https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/WikimediaEvents/+/437686/
|
|
mw.track( 'wikimedia.event.ReadingDepthSchema.enable' );
|
|
}
|
|
|
|
/**
|
|
* Gets the users AB-test bucket
|
|
*
|
|
* @return {string} AB-test bucket, CONTROL_BUCKET by default, "A" or "B" buckets otherwise.
|
|
*/
|
|
function getBucket() {
|
|
return mwExperiments.getBucket( test, sessionId );
|
|
}
|
|
|
|
/**
|
|
* Checks whether or not a user is in the AB-test,
|
|
*
|
|
* @return {boolean}
|
|
*/
|
|
function isEnabled() {
|
|
return getBucket() !== CONTROL_BUCKET;
|
|
}
|
|
|
|
/**
|
|
* Initiates the AB-test.
|
|
*
|
|
* return {void}
|
|
*/
|
|
function init() {
|
|
if ( isEnabled() ) {
|
|
startABTest();
|
|
}
|
|
}
|
|
|
|
init();
|
|
|
|
return {
|
|
getBucket: getBucket,
|
|
isEnabled: isEnabled
|
|
};
|
|
}
|
|
|
|
M.define( 'skins.minerva.scripts/AB', AB );
|
|
|
|
}( mw, mw.mobileFrontend, mw.experiments ) );
|