MyDataHelps applications can subscribe to events. Since applications may remain in memory indefinitely on iOS and Android, it is often necessary to listen for these events to know when to refresh the data being displayed.

Subscribe to an Event

MyDataHelps.on(eventName, callback)

Triggers the callback when the specified event occurs. Current events supported are:

  • applicationBecameVisible - Triggers whenever the application becomes visible. For instance if:
    • MyDataHelps is foregrounded and this application was open.
    • The participant selects the tab for this application.
    • An application presented by this application is dismissed.
  • surveyDidFinish - Triggers whenever a survey is finished. The event contains a “reason” parameter to determine if the survey was completed or cancelled.
Example: Using surveyDidFinish to Act on Survey Results
function refreshApplicationState(reason) {
  //Get the current date at midnight
  var today = new Date().setHours(0,0,0,0);

  //Query for survey answers from the MoodRating step recorded anytime today.
  var surveyQueryParams = {
    stepIdentifier: "MoodRating",
    after: today

  var lowMoodThreshold = 4;

    .then(function(answerPage) {

      //For simplicity, assume there is exactly 0 or 1 responses to this survey step today.
      if (answerPage.surveyAnswers[0] && 
        answerPage.surveyAnswers[0].answers[0] &&
        parseInt(answerPage.surveyAnswers[0].answers[0]) <= lowMoodThreshold) {

        //Show the participant resources to help their mood.


MyDataHelps.on('surveyDidFinish', refreshApplicationState);