Push notification in case of inactivity

After I have configured the push notificatin after the nice introduction how can I set up the app so that after a period of inactivity (when the app is no longer used) the user is notified by push messages? In this way, he can be motivated to open the app again

Hi Ramo,

There is - as always - many ways to do it. I have implemented the following logic in our MAX - Your Asthma Coach intervention with the help of the Execution on PERIODIC BASIS rule tree:

  1. Calculate the $minutesSinceLastLogout with execute Javascript

var now = new Date('$systemYear'*1, '$systemMonth'*1-1, '$systemDayOfMonth'*1, '$systemHourOfDay'*1, '$systemMinuteOfHour'*1); 

var lastLogoutDateRaw = '$participantLastLogoutDate'.split(".");
var day = Number(lastLogoutDateRaw[0]);
var month = Number(lastLogoutDateRaw[1])-1;
var year = Number(lastLogoutDateRaw[2]);

var lastLogoutTime = '$participantLastLogoutTime'*1;
var hour = Math.floor(lastLogoutTime);
var min = Math.floor((lastLogoutTime * 60) % 60);

var lastLogout = new Date(year, month, day, hour, min, 0, 0);

var newLessonStarted = new Date('$newLessonStartedYear'*1, '$newLessonStartedMonth'*1-1, '$newLessonStartedDayOfMonth'*1, '$newLessonStartedHourOfDay'*1, '$newLessonStartedMinuteOfHour'*1);

if (newLessonStarted.getTime() > lastLogout.getTime()){
  dt2 = newLessonStarted;
} else {
  dt2 = lastLogout;
}

var diff =(dt2.getTime() - now.getTime()) / 1000;
diff /= 60;
diff = Math.abs(Math.round(diff));

var x = { 'participantInactiveInMinutes' : diff};
x;
  1. Send out a 60min push-only reminder

a)


You see also that I increment the $60minReminderSentFrequency variable so that I can report the number of sent 60-min reminders later in a scientific paper, too.
b)

c)

d)

Just consider to remember in a corresponding boolean variable that the 60-min reminder has been sent. Otherwise, the reminder is sent out several times which is not what we want. Also, consider the situation that a participant interacts again, so the participantInactiveInMinutes needs to be reset. Finally, also consider the situation that the participant is finished with a particular coaching session; then you also do not wan to remind him.

I apply then a similar approach for a 1-day of inactivity reminder, 3-day of inactivity reminder, etc. I hope this gives you a first idea of how you can implement this on your own. A final note: In general, I do not recommend the use of the Execution on PERIODIC BASIS rule tree for actions and events (e.g. notifications and reminders) that have a > 24h notification perspective because that rule tree is executed several times each hour for each participant and thus, may significantly decrease server and intervention performance. Rather use, for example, the daily rule tree for these “long-term” aspects.

But for now: Enjoy your implementation and many greetings,
Tobi

1 Like

Thanks Tobi for the detailed answer.

As you recommended I created the rule under “Execution on DAILY BASIS”.
I have configured the push notifications so that I receive notifications from normal chat messages. I assume if my rule works properly I should get a reminder notification.

Unfortunately my rule didn’t work and looks like this:

a) I have created the following variables

  • $participantInactiveInOneDay without value
  • $1dayReminderSentFreq without value
  • $1dayReminderSent set to false

b) my rule tree looks like this:

c) 1 day push-only reminder:

d) 1dayReminderSent:

e) push-only reminder:

f) 1dayReminder Message Group:

g) 1dayReminderSentFeq+1:

h) and

After I created the rule I moved the app to the background and jumped a day forward with Time Simulator. Unfortunately I still did not receive any push notification. What could be the problem?

Thanks for your invested time!

Ramo

Hi Ramo,

Where and how do calculate the $participantInactiveInOneDay? This should be done in the daily rule tree, too (once at the beginning for participants that have not yet finished the intervention. This calculation seems to be missing here (at least there is no screenshot or code on it). Moreover, please use the $participantInactiveInOneDay as a debug variable and cross-check the value of it. That is, give it out in the conversational turns or cross-check it in the results section of MobileCoach Designer (see screenshot). This variable must have the “right value” before a message will be triggered.

I hope this helps for a next step?

Best, Tobi

1 Like

Thanks Tobias. Unfortunately I don’t quite understand. Where should I have calculated the variable $participantInactiveInOneDay?

I understood in your previous answer that you suggested 2 possible solutions. I decided on the second solution with an Execution on DAILY BASIS rule. Or does the first part (where the JavaScript code is added) also belong to the solution? Should I have implemented the first part as well?

best
Ramo

Hi Ramo,

Well, $participantInactiveInOneDay needs to be filled with a value (e.g. from a calculation that considers the time of inactivity). The Javascript code may be one option but the general notion is that you need to calculate - on a regular - basis (either on a daily basis or more frequently) whether a participant was inactive and to store that value in an appropriate variable (e.g. $participantInactiveInOneDay). That is, you need some calculation on it. Otherwise, $participantInactiveInOneDay never changes its value (e.g. is always 0 / false and you cannot work with it.

Best, Tobi

1 Like