Stage 4 - Snooze Feature

Stage 4 - Customizing the Snooze Feature

How to customize the snooze feature in Experience Sampler

In this stage, we will customize several functions. This stage will also introduce you to the notification scheduling function, which we will use more in the next stage. If you do not want to include a snooze function, we would still highly recommend that you read over this page to begin to familiarize yourself with the notification scheduling function and be aware of the lines of code that should remain commented out.

recordResponse function

The recordResponse function is the first function that needs to be customized. First find the following line:
     else if (count == SNOOZEQ && response == X) {app.renderLastPage(lastPage[Y], count);}
where
X is the response value associated with the participant choosing to snooze the app.
Y is the index number of the end-of-questionnaire message that you would like to display when the participant chooses to snooze the app.
The default for this line based on the template should be:
     else if (count == SNOOZEQ && response == 0) {app.renderLastPage(lastPage[1], count);}

renderLastPage function

This function specifies the appearance of the last page screen, schedules the snooze notification if the app is on the snooze question, and sends the data to the server. We have called this function several times before when we customized the question logic for the questionnaire in Stage 3.
To specify when to call the snooze scheduling function (app.snoozeNotif();), you simply have to customize the following line:
     renderLastPage: function(pageData, question_index) {
          $("#question").html(Mustache.render(lastPageTmpl, pageData));
          if ( question_index == X ) {
               app.snoozeNotif();
               localStore.snoozed = Y;
          }
          app.saveDataLastPage();
     },
where
X is the index number of the snooze question.
Y is the response value associated with the participant choosing to snooze the app.

snoozeNotif function

To customize the properties the snooze notification, you will need to customize the snoozeNotif function:
     snoozeNotif: function() {
          var now = new Date().getTime(), snoozeDate = new Date(now + X*1000);
          var id = ‘notification id number’;
          window.plugin.notification.local.add({
               icon: 'name of icon to appear with notification (for Android)',
               id: id,
               message: 'message to be shown to participants in notification’,
               autoCancel: true,
               date: snoozeDate,
          });
     }
where
X is the number of seconds that will elapse between the time participants press snooze and when the snooze reminder will fire (e.g., 600 for 10 minutes).
Thus, the snoozeDate variable represents the time when the snooze notification will be fired. This value is multiplied by 1000 because the local notification plugin we used calculates time in milliseconds.
For more information about the other properties, see katzer's README.

sampleParticipant Function

This function allows you to specify a lockout period. This provides with some flexibility to multitask while completing the questionnaire.
The lockout period is the amount of time that has to elapse before the participants have to restart the questionnaire. For example, in our study we specified a lockout period of 10 minutes. This means that if a participant was in the process of completing our questionnaire and exited the app to answer a text message they received, they could pick up where they left off in the questionnaire if they return to the app within 10 minutes of exiting the app. But if the participant returns to the app after 11 minutes have passed, he or she would have to restart the questionnaire.
The lockout period is also the minimum amount of time between sets of responses. That is, if the lockout period is set for 10 minutes, participants must wait 10 minutes after finishing the questionnaire to do another questionnaire. This allows you to prevent participants from hoarding questionnaires.

You can specify these time periods separately with additional conditional statements:
     sampleParticipant: function() {
          var current_moment = new Date();
          var current_time = current_moment.getTime();
          if ((current_time - localStore.pause_time) > X){
               localStore.snoozed = Y;
               app.renderQuestion(0);
          }
          if (localStore.snoozed == Z) {
               localStore.snoozed = Y;
               app.renderQuestion(B);
          }
          app.saveData();
     },
where
X is the lockout period in milliseconds (e.g., 10 minutes is 600 000 ms)
Y is the snooze question response value associated with choosing NOT to snooze the app
0 in the app.renderQuestion function indicates that the app should start at the beginning of the survey. If the app should start at a different question, you can change the value to the index number that corresponds with the question that should appear.

Now you're ready to move on to customizing your signalling schedulein!

Stage 1 - Questions and Messages

Learn how to customize your survey questions, end-of-questionnaire messages, and participant setup questions.

More

Testing the App

It's important to test your app after each customization stage. Learn how to test your app on a smartphone emulator.

More

Stage 2 - Saving the Data

In this stage, you'll learn how to set up your server and app to save your questionnaire data.

More

Stage 3 - Advanced Survey Features

In this stage, you'll learn how to implement skip logic, question branching, and piped text for your questionnaire.

More

Stage 4 - Snooze Function

Implement a snooze function to remind participants to complete questionnaires at a later time if they are currently busy.

More

Stage 5 - Scheduling Notifications

Schedule your signals for either a signal-contingent design (with random or fixed intervals) or an interval-contingent design.

More