1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/app/scripts/controllers/ab-test.js
Dan J Miller 1bd22b58c0
Add a/b test for full screen transaction confirmations (#7162)
* Adds ab test controller with a fullScreenVsPopup test

* Add migration for fullScreenVsPopup state

* Move abtest state under an 'abtests' object.

* MetaMask shows fullScreen group of a/b test unapproved txs in a full browser tab

* Ensure cancel metrics event in confirm-transaction-base.component.js is sent in all cases

* Switch to existing tab for unapproved tx if it exists when opening in full screen

* Send metrics event for entering a/b test from confirm screen

* Fix lint, unit and integration tests related to a/b test code

* Remove unnecessary tabs.query call in triggerUiInNewTab
2019-09-24 17:08:38 -04:00

58 lines
1.7 KiB
JavaScript

const ObservableStore = require('obs-store')
const extend = require('xtend')
const { getRandomArrayItem } = require('../lib/util')
/**
* a/b test descriptions:
* - `fullScreenVsPopup`:
* - description: tests whether showing tx confirmations in full screen in the browser will increase rates of successful
* confirmations
* - groups:
* - popup: this is the control group, which follows the current UX of showing tx confirmations in the notification
* window
* - fullScreen: this is the only test group, which will cause users to be shown tx confirmations in a full screen
* browser tab
*/
class ABTestController {
/**
* @constructor
* @param opts
*/
constructor (opts = {}) {
const { initState } = opts
this.store = new ObservableStore(extend({
abTests: {
fullScreenVsPopup: this._getRandomizedTestGroupName('fullScreenVsPopup'),
},
}, initState))
}
/**
* Returns the name of the test group to which the current user has been assigned
* @param {string} abTestKey the key of the a/b test
* @return {string} the name of the assigned test group
*/
getAssignedABTestGroupName (abTestKey) {
return this.store.getState().abTests[abTestKey]
}
/**
* Returns a randomly chosen name of a test group from a given a/b test
* @param {string} abTestKey the key of the a/b test
* @return {string} the name of the randomly selected test group
* @private
*/
_getRandomizedTestGroupName (abTestKey) {
const nameArray = ABTestController.abTestGroupNames[abTestKey]
return getRandomArrayItem(nameArray)
}
}
ABTestController.abTestGroupNames = {
fullScreenVsPopup: ['control', 'fullScreen'],
}
module.exports = ABTestController