Skip to content

Commit 0b1918a

Browse files
committed
prep for A/B testing of survey q
1 parent 1f03537 commit 0b1918a

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

‎v3/js/opt-frontend-common.js‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,15 +1270,35 @@ function getSurveyObject() {
12701270
*/
12711271

12721272
/* v4 */
1273-
var what_learn_Q_val = $('#what-learn-Q').val();
1274-
1275-
var ret = null;
1273+
var ret = {
1274+
ver: $('#Q-version').val(),
1275+
}
12761276

1277-
if (what_learn_Q_val) {
1278-
ret = {
1279-
ver: $('#Q-version').val(),
1280-
what_learn_Q: what_learn_Q_val,
1277+
var what_learn_Q_val = $('#what-learn-Q').val();
1278+
if ($.trim(what_learn_Q_val)) {
1279+
ret.what_learn_Q = what_learn_Q_val;
1280+
ret.testing_group = 'c'; // special group for users who have filled out this
1281+
// execution-time survey
1282+
} else {
1283+
// assign to 'a' or 'b' group for A/B testing:
1284+
var grp = 'ERROR'; // default error sentinel
1285+
1286+
// if we have localStorage, then get/set a testing_group field to ensure
1287+
// some consistency across different sessions from the same user.
1288+
// of course, this isn't foolproof by any means, but it's a start
1289+
if (supports_html5_storage()) {
1290+
var saved_grp = localStorage.getItem('testing_group');
1291+
if (saved_grp) {
1292+
grp = saved_grp;
1293+
} else {
1294+
grp = (Math.random() < 0.5) ? 'a' : 'b';
1295+
localStorage.setItem('testing_group', grp);
1296+
}
1297+
} else {
1298+
grp = (Math.random() < 0.5) ? 'a' : 'b';
12811299
}
1300+
1301+
ret.testing_group = grp;
12821302
}
12831303

12841304
return ret;

0 commit comments

Comments
 (0)