Skip to content

Commit 579867b

Browse files
committed
added a noRepeats option to get live help survey questions
so that we don't show each user the same question again
1 parent 3589c35 commit 579867b

1 file changed

Lines changed: 47 additions & 16 deletions

File tree

v5-unity/js/opt-shared-sessions.ts

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ var liveHelpSurvey = {
243243
*/
244244

245245
// 2018-03-17: minor tweaks on version 4's wording to make it sound a bit more optional and casual
246+
/*
246247
var liveHelpSurvey = {
247248
requestHelp: [ {prompt: 'You are now on the help queue. Please wait for help to arrive.\n\n[OPTIONAL] Support our research by letting us know:\nWhy did you decide to ask for help at this time?',
248249
v: 'r4a'},
@@ -255,14 +256,32 @@ var liveHelpSurvey = {
255256
v: 'h4b'},
256257
]
257258
};
259+
*/
258260

261+
// 2018-06-24: version 5 is nearly identical to version 4, except that I turned
262+
// on noRepeats=true so we don't ask users the same question more than once
263+
var liveHelpSurvey = {
264+
requestHelp: [ {prompt: 'You are now on the help queue. Please wait for help to arrive.\n\nSupport our research by letting us know:\nWhy did you decide to ask for help at this time?',
265+
v: 'r5a'},
266+
{prompt: 'You are now on the help queue. Please wait for help to arrive.\n\nSupport our research by letting us know:\nWhy did you ask for help anonymously on this website rather than getting help from someone you know?',
267+
v: 'r5b'},
268+
],
269+
volunteerHelp: [ {prompt: "Thanks for volunteering! You are about to join a live chat.\n\nSupport our research by letting us know:\nWhy did you decide to volunteer at this time? What motivated you to click on this particular help link?",
270+
v: 'h5a'},
271+
{prompt: "Thanks for volunteering! You are about to join a live chat.\n\nSupport our research by letting us know:\nWhat is your current job or profession?",
272+
v: 'h5b'},
273+
]
274+
};
259275

260276

261277

262278
// randomly picks a survey item from liveHelpSurvey and mutates
263279
// localStorage to record that this has been randomly picked, so it won't
264280
// be picked again during the next call
265-
function randomlyPickSurveyItem(key) {
281+
//
282+
// 2018-06-24: if noRepeats is true, then don't ask this user repeated
283+
// questions; simply return null if all questions have already been asked
284+
function randomlyPickSurveyItem(key, noRepeats=false) {
266285
var lst = liveHelpSurvey[key];
267286
var filteredLst = [];
268287

@@ -281,6 +300,10 @@ function randomlyPickSurveyItem(key) {
281300
// if ALL entries have been filtered out, then reset everything and
282301
// start from scratch:
283302
if (filteredLst.length == 0) {
303+
if (noRepeats) {
304+
return null; // punt early if noRepeats=true!!!
305+
}
306+
284307
if (supports_html5_storage()) {
285308
lst.forEach((e) => {
286309
localStorage.removeItem(e.v);
@@ -710,7 +733,12 @@ Get live help!
710733
// add these handlers AFTER the respective DOM nodes have been added above:
711734

712735
$(".gotoHelpLink").click(function() {
713-
var surveyItem = randomlyPickSurveyItem('volunteerHelp');
736+
// 2018-06-24: don't show the user repeated questions (noRepeats=true)
737+
var surveyItem = randomlyPickSurveyItem('volunteerHelp', true);
738+
if (!surveyItem) {
739+
// punt early!
740+
return true; // ALWAYS cause the link to be clicked
741+
}
714742
var miniSurveyResponse = prompt(surveyItem.prompt);
715743

716744
// always log every impression, even if miniSurveyResponse is blank,
@@ -1601,20 +1629,23 @@ Get live help!
16011629
// pop up the survey BEFORE you make the request, so in case you get
16021630
// hung up on the prompt() and take a long time to answer the question,
16031631
// you're not put on the queue yet until you finish or click Cancel:
1604-
var surveyItem = randomlyPickSurveyItem('requestHelp');
1605-
var miniSurveyResponse = prompt(surveyItem.prompt);
1606-
1607-
// always log every impression, even if miniSurveyResponse is blank,
1608-
// since we can know how many times that survey question was ever seen:
1609-
var surveyUrl = TogetherJS.config.get("hubBase").replace(/\/*$/, "") + "/survey";
1610-
$.ajax({
1611-
url: surveyUrl,
1612-
dataType: "json",
1613-
data: {id: shareId, user_uuid: this.userUUID, kind: 'requestHelp', v: surveyItem.v, response: miniSurveyResponse},
1614-
success: function() {}, // NOP
1615-
error: function() {}, // NOP
1616-
});
1617-
1632+
//
1633+
// 2018-06-24: don't show the user repeated questions (noRepeats=true)
1634+
var surveyItem = randomlyPickSurveyItem('requestHelp', true);
1635+
if (surveyItem) {
1636+
var miniSurveyResponse = prompt(surveyItem.prompt);
1637+
1638+
// always log every impression, even if miniSurveyResponse is blank,
1639+
// since we can know how many times that survey question was ever seen:
1640+
var surveyUrl = TogetherJS.config.get("hubBase").replace(/\/*$/, "") + "/survey";
1641+
$.ajax({
1642+
url: surveyUrl,
1643+
dataType: "json",
1644+
data: {id: shareId, user_uuid: this.userUUID, kind: 'requestHelp', v: surveyItem.v, response: miniSurveyResponse},
1645+
success: function() {}, // NOP
1646+
error: function() {}, // NOP
1647+
});
1648+
}
16181649

16191650
this.iMadeAPublicHelpRequest = true; // this will always be true even if you shut the door later and don't let people in (i.e., make this into a private session)
16201651

0 commit comments

Comments
 (0)