parent
b82177dc44
commit
23ecb632eb
9 changed files with 157 additions and 82 deletions
|
@ -1,6 +1,22 @@
|
|||
import hash from 'string-hash';
|
||||
import Account from './ui/account';
|
||||
|
||||
const experiments = {};
|
||||
const experiments = {
|
||||
signin_button_color: {
|
||||
eligible: function() {
|
||||
return true;
|
||||
},
|
||||
variant: function() {
|
||||
return ['white-blue', 'blue', 'white-violet', 'violet'][
|
||||
Math.floor(Math.random() * 4)
|
||||
];
|
||||
},
|
||||
run: function(variant, state) {
|
||||
const account = state.cache(Account, 'account');
|
||||
account.buttonClass = variant;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Returns a number between 0 and 1
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
@ -25,23 +41,12 @@ export default function initialize(state, emitter) {
|
|||
xp.run(+state.query.v, state, emitter);
|
||||
}
|
||||
});
|
||||
|
||||
if (!state.storage.get('testpilot_ga__cid')) {
|
||||
// first ever visit. check again after cid is assigned.
|
||||
emitter.on('DOMContentLoaded', () => {
|
||||
checkExperiments(state, emitter);
|
||||
});
|
||||
const enrolled = state.storage.enrolled;
|
||||
// single experiment per session for now
|
||||
const id = Object.keys(enrolled)[0];
|
||||
if (Object.keys(experiments).includes(id)) {
|
||||
experiments[id].run(enrolled[id], state, emitter);
|
||||
} else {
|
||||
const enrolled = state.storage.enrolled.filter(([id, variant]) => {
|
||||
const xp = experiments[id];
|
||||
if (xp) {
|
||||
xp.run(variant, state, emitter);
|
||||
}
|
||||
return !!xp;
|
||||
});
|
||||
// single experiment per session for now
|
||||
if (enrolled.length === 0) {
|
||||
checkExperiments(state, emitter);
|
||||
}
|
||||
checkExperiments(state, emitter);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue