-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
13 changed files
with
240 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const version = 38 | ||
const clone = require('clone') | ||
const ABTestController = require('../controllers/ab-test') | ||
const { getRandomArrayItem } = require('../lib/util') | ||
|
||
/** | ||
* The purpose of this migration is to assign all users to a test group for the fullScreenVsPopup a/b test | ||
*/ | ||
module.exports = { | ||
version, | ||
migrate: async function (originalVersionedData) { | ||
const versionedData = clone(originalVersionedData) | ||
versionedData.meta.version = version | ||
const state = versionedData.data | ||
versionedData.data = transformState(state) | ||
return versionedData | ||
}, | ||
} | ||
|
||
function transformState (state) { | ||
const { ABTestController: ABTestControllerState = {} } = state | ||
const { abTests = {} } = ABTestControllerState | ||
|
||
if (!abTests.fullScreenVsPopup) { | ||
state = { | ||
...state, | ||
ABTestController: { | ||
...ABTestControllerState, | ||
abTests: { | ||
...abTests, | ||
fullScreenVsPopup: getRandomArrayItem(ABTestController.abTestGroupNames.fullScreenVsPopup), | ||
}, | ||
}, | ||
} | ||
} | ||
return state | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,5 @@ module.exports = [ | |
require('./035'), | ||
require('./036'), | ||
require('./037'), | ||
require('./038'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const assert = require('assert') | ||
const migration38 = require('../../../app/scripts/migrations/038') | ||
|
||
describe('migration #38', () => { | ||
it('should update the version metadata', (done) => { | ||
const oldStorage = { | ||
'meta': { | ||
'version': 37, | ||
}, | ||
'data': {}, | ||
} | ||
|
||
migration38.migrate(oldStorage) | ||
.then((newStorage) => { | ||
assert.deepEqual(newStorage.meta, { | ||
'version': 38, | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should add a fullScreenVsPopup property set to either "control" or "fullScreen"', (done) => { | ||
const oldStorage = { | ||
'meta': {}, | ||
'data': {}, | ||
} | ||
|
||
migration38.migrate(oldStorage) | ||
.then((newStorage) => { | ||
assert(newStorage.data.ABTestController.abTests.fullScreenVsPopup.match(/control|fullScreen/)) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should leave the fullScreenVsPopup property unchanged if it exists', (done) => { | ||
const oldStorage = { | ||
'meta': {}, | ||
'data': { | ||
'ABTestController': { | ||
abTests: { | ||
'fullScreenVsPopup': 'fullScreen', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
migration38.migrate(oldStorage) | ||
.then((newStorage) => { | ||
assert.deepEqual(newStorage.data.ABTestController, { | ||
abTests: { | ||
'fullScreenVsPopup': 'fullScreen', | ||
}, | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.