Implementing a JITAI: which triggers work reliably on iPhone and Android

On a smartphone, “just in time” usually means “within minutes”. How quickly and how reliably a rule triggers depends on the trigger, the operating system and where the decision is made.

Updated on

Why does “just in time” usually mean minutes?

Several steps lie between an event in daily life and a person's response: the operating system detects the event, wakes the app, the app evaluates the rule, a notification appears, and the person notices it. Each step takes time, and operating systems batch background work.

Then comes the person's reaction time. In the Q Sense study, 50.0% of geofence-triggered notifications (137 of 274) were tapped within 30 minutes (Naughton et al., 2016). Plan proximal outcomes with time windows that tolerate a delay of a few minutes.

Triggers compared

The entries for place, step count, app usage and wearable data describe the current state in PULSE. The time-of-day row follows the operating systems' documentation.

TriggeriPhoneAndroidTypical delayWhat to watch
Answer in a surveyChecked on submission, inside the appAs on iPhoneNone, the follow-up task opens in the same sessionDecision points only arise when the survey is answered
Time of dayVisible notification at the scheduled timeLikewise; in Doze the system defers network access and standard alarmsDepends on the delivery route; delays possible in DozeNotifications must be allowed; schedule times in the person's local time
Place (geofence)Entering and leaving, detected by the system; about 20 zones per appEntering and leaving, detected by the system; about 100 zones per appSeconds to a few minutesLocation permission “Always”, radius of 100 m or more, minimum stay against false triggers
Step countNo event from the system; the app checks when it is woken or openedAs on iPhoneOften 15 minutes or more after the end of the time windowMissing data are not zero steps; do not place the window at the end of the day
App usageUsage duration from iOS 16 with Screen Time access; the person selects the apps; frequent opening not availableUsage duration and frequent opening for specified apps, with usage accessAndroid almost in real time, iPhone usually a few minutesOn iPhone the app list is no technical restriction
Data from wearablesVia Apple Health, only after the watch has synced with the phoneVia Health Connect, likewise no live dataDepends on the sync, often several hours with an Apple WatchSuitable for real-time triggers only if the sensor delivers directly to the app

Triggers that arise in the foreground, such as survey answers, do not depend on background limits. The operating system detects changes of place itself and wakes the app. Step count and wearable data reach the app only when it is woken or the watch has synced. Sense2Stop is an example of real-time sensor data: the smartphone continuously processes data from dedicated chest and wrist sensors and classifies each minute as probably stressed or not (Battalio et al., 2021).

Background restrictions of the operating systems

  • iPhone, place: the system monitors the zones and launches the app when the state changes. An app may monitor at most 20 conditions at a time, and after a reboot monitoring only starts once the device has been unlocked (Apple, Core Location).
  • iPhone, silent wake-ups: the system treats background notifications as low priority and does not guarantee delivery. Apple advises sending no more than two or three per hour (Apple, User Notifications). This route is therefore risky for time-critical rules.
  • Android, Doze: when a device lies stationary with the screen off for some time and is not charging, Doze defers network access, jobs and standard alarms to maintenance windows. Even the alarms designed for this fire at most once every nine minutes per app (Android Developers, Doze).
  • Android, place: according to the documentation the latency is usually under two minutes, two to three minutes on average with background limits, and up to six after a long stationary period. The limit is 100 zones per app, a radius of at least 100 to 150 metres is recommended, and alerts may fail without a data connection (Android Developers, Geofencing).
  • Android, manufacturers: some stop background apps by their own rules.

The role of push notifications

The notification is how an intervention reaches the person. A local notification is created by the app on the device and needs no network. A push message comes from the server and needs a connection. If participants have turned notifications off, neither reaches them.

A micro-randomised trial with 1,255 users of a workplace well-being app over 89 days shows how small the effect of a single notification can be: when a push notification with a tailored health message was sent, a self-monitoring entry in the app within the following 24 hours was 3.9% more likely (risk ratio 1.039; 95% CI 1.01 to 1.08; Bidargaddi et al., 2018).

Deciding on the device or on the server

CriterionOn the deviceOn the server
SpeedRight after the eventAfter the data upload and a push in return
Without networkRule keeps runningNo decision possible
Data protectionRaw data such as place coordinates can stay on the deviceData have to reach the server
Changing rulesNew rules first have to reach every deviceEffective for everyone immediately
LogArrives with the next transmissionAvailable centrally straight away

Events such as place or app usage belong on the device. Rules that combine data from many days or several sources are easier to implement on the server.

Offline behaviour

With decisions on the device, rules keep running without a network, and triggers and answers reach the server later. Analyse by the time of the event, never by the time of arrival. Decide in advance how you treat triggers whose response window expired while the device was offline.

What does this mean for micro-randomised trials?

In a micro-randomised trial, randomisation is repeated at every decision point (Qian et al., 2022). This places three demands on the technology:

  • Randomisation happens where the decision is made. With decisions on the device, the device has to draw the allocation and log it together with its probability.
  • Availability is recorded for every decision point. Bidargaddi et al. randomised only available users. Define in advance when someone counts as unavailable, for example with notifications turned off or a device without a network.
  • The time window of the proximal outcome starts with randomisation, as in HeartSteps with the 30 minutes that follow (Klasnja et al., 2019). If the message arrives late, the time in which it can have an effect shrinks. Log the time of delivery as well.

Testing before the start

  1. Test every trigger for real on at least one iPhone and one Android phone.
  2. Measure the delay several times, including with the screen locked and after a longer idle period.
  3. Check special cases: flight mode, reboot, notifications turned off, permission revoked.
  4. Test an Android phone from a manufacturer with strict battery optimisation.
  5. Compare the log with your notes: do the number and times of the triggers match?

Frequently asked questions

How quickly does a JITAI respond to a change of location?

Usually within seconds to a few minutes. The Android documentation states mostly under two minutes and up to six after a long stationary period. A minimum stay deliberately lengthens the response time but prevents triggers when someone merely walks past.

Do JITAI triggers work when the smartphone is offline?

Yes, if the rule is evaluated on the device. Triggers and answers are transmitted once the connection returns. Rules on the server and push messages need a connection, and place detection on Android may fail without a data connection.

Can a smartwatch trigger a JITAI?

Via Apple Health or Health Connect only with a delay, because the values are available only after syncing with the phone. Real-time triggers need sensors that send directly to the app, as in Sense2Stop.

Why does a JITAI trigger later on iPhone than on Android?

In PULSE this applies to app usage. Android reports it almost in real time, while on iPhone the notification usually arrives within a few minutes. For place and step count, similar delays are documented on both platforms.

With PULSE

In PULSE, the research platform of the Center for Computation of Human Behavior, the PULSE Research App evaluates event-based triggers on the device; results reach the admin panel with the next transmission. Available triggers are answers in a survey, fixed and random times in participants' local time, entering or leaving a place, the step count within a time window and the use of particular apps. A trigger based on wearable data is not among the documented triggers. The place trigger needs the location permission “Always”, and self-marked places stay on the device with their coordinates. The step count trigger checks at the end of the time window and is skipped for the day if the app does not become active before midnight. Frequent opening of apps works on Android only. On iPhone, Background App Refresh has to be switched on. Changed rules reach the app when participants open the overview. Triggers cannot be fired manually, so tests run for real in the study's test state; the app logs show fired, suppressed and expired triggers.

Further reading

Sources

  1. Apple Inc. (n.d.). Monitoring the user's proximity to geographic regions. Apple Developer Documentation, Core Location. https://developer.apple.com/documentation/corelocation/monitoring-the-user-s-proximity-to-geographic-regions
  2. Apple Inc. (n.d.). Pushing background updates to your App. Apple Developer Documentation, User Notifications. https://developer.apple.com/documentation/usernotifications/pushing-background-updates-to-your-app
  3. Android Developers (n.d.). Optimize for Doze and App Standby. Google. https://developer.android.com/training/monitoring-device-state/doze-standby
  4. Android Developers (n.d.). Create and monitor geofences. Google. https://developer.android.com/develop/sensors-and-location/location/geofencing
  5. Naughton, F., Hopewell, S., Lathia, N., Schalbroeck, R., Brown, C., Mascolo, C., McEwen, A., & Sutton, S. (2016). A Context-Sensing Mobile Phone App (Q Sense) for Smoking Cessation: A Mixed-Methods Study. JMIR mHealth and uHealth, 4(3), e106. https://doi.org/10.2196/mhealth.5787
  6. Klasnja, P., Smith, S., Seewald, N. J., Lee, A., Hall, K., Luers, B., Hekler, E. B., & Murphy, S. A. (2019). Efficacy of Contextually Tailored Suggestions for Physical Activity: A Micro-randomized Optimization Trial of HeartSteps. Annals of Behavioral Medicine, 53(6), 573-582. https://doi.org/10.1093/abm/kay067
  7. Battalio, S. L., Conroy, D. E., Dempsey, W., Liao, P., Menictas, M., Murphy, S., Nahum-Shani, I., Qian, T., Kumar, S., & Spring, B. (2021). Sense2Stop: A micro-randomized trial using wearable sensors to optimize a just-in-time-adaptive stress management intervention for smoking relapse prevention. Contemporary Clinical Trials, 109, 106534. https://doi.org/10.1016/j.cct.2021.106534
  8. Bidargaddi, N., Almirall, D., Murphy, S., Nahum-Shani, I., Kovalcik, M., Pituch, T., Maaieh, H., & Strecher, V. (2018). To Prompt or Not to Prompt? A Microrandomized Trial of Time-Varying Push Notifications to Increase Proximal Engagement With a Mobile Health App. JMIR mHealth and uHealth, 6(11), e10123. https://doi.org/10.2196/10123
  9. Qian, T., Walton, A. E., Collins, L. M., Klasnja, P., Lanza, S. T., Nahum-Shani, I., Rabbi, M., Russell, M. A., Walton, M. A., Yoo, H., & Murphy, S. A. (2022). The microrandomized trial for developing digital interventions: Experimental design and data analysis considerations. Psychological Methods, 27(5), 874-894. https://doi.org/10.1037/met0000283