PennController for IBEX › Forums › Support › Restricting to desktop
- This topic has 6 replies, 4 voices, and was last updated 2 years, 7 months ago by
Jeremy.
-
AuthorPosts
-
July 7, 2020 at 2:15 pm #5767
kmoulton
ParticipantHi,
I’ve searched through the forum here and don’t *think* I’ve seen this issue exactly addressed, but forgive me if it is. We want to ensure that only desktop users (or at least not phones) can do our SPR study – or at least to have a way of tracking this. I’ve seen other experiments that have browser/OS checks and so on, but I do not know how that is done and if it would help. Any thoughts/tips?
Thanks
July 7, 2020 at 5:37 pm #5770Jeremy
KeymasterHi,
There’s no bulletproof method to ensure that someone is using a desktop rather than a phone or a tablet, but there are good approximation methods.
One option is to check the width of the screen:
newTrial( newFunction( ()=>window.matchMedia("only screen and (max-width: 760px)").matches ) .test.is(true) .success( newText("<p>We're sorry but this experiment requires a wider resolution.</p>"+ "<p>Please do not use a modile device to take this experiment.</p>"+ "<p>If you are using a desktop browser, make sure to maximize this window.</p>") .print() , newButton().wait() ) )
Another solution is to use user agent sniffing:
newFunction( ()=>navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i) ) .testNot.is(null)
Jeremy
July 8, 2020 at 9:00 am #5774florians
ModeratorAnother simple feature that makes it at least very hard (possibly impossible, not sure) to proceed in an experiment with a device without a physical keyboard is to just include a ‘press space to continue’ step, using newKey(). Without a text input field, there generally is no straightforward way (if any, haven’t found one) to bring up the virtual keyboard on a phone or iPad, which means you cannot continue. (I learned this by accident in a recent study where I was leaving tablet use as an option on Prolific, and had lots of people falter precisely for this reason.) Thinking on it, I wonder whether self-paced reading would work on devices without a keyboard to begin with – is there any way to proceed within a sentence without pressing a keyboard key?
July 13, 2020 at 2:44 pm #5792kmoulton
Participantthanks!!
As for spr even being possible on a phone: i found that iphones (n=2 types) would display a “Next” button to progress through the regions (but yes – as you say – I get stalled at a “press any key to continue” screen). I was just surprise that this Next button appears on the phone when on a desktop one just presses the spacebar to proceed. This is native Ibex.July 13, 2020 at 4:55 pm #5793Jeremy
KeymasterAlex Drummond wrote this in utils.js: var isIPhone = navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i);
And the code of DashedSentence contains a conditional on isIPhone to print the “Next” button. I guess the longer term idea was to expand the check to any mobile browser (remember that Alex started writing ibex in the early 2010s)
Jeremy
January 18, 2022 at 3:56 am #7673murphybeck
ParticipantUser Agent detection is not a recommended technique for modern web apps. You can use JavaScript window.matchMedia() method to detect a mobile device based on the CSS media query.
if (window.matchMedia("(max-width: 767px)").matches) { // The viewport is less than 768 pixels wide document.write("This is a mobile device."); }
Another approach would be a responsive media query. You could presume that a mobile phone has a screen size greater than x and less than y.
For example:
@media only screen and (min-width: 320px) and (max-width: 600px) {}
You may also use navigator.userAgentData.mobile .
const isMobile = navigator.userAgentData.mobile;
January 18, 2022 at 7:10 pm #7679Jeremy
KeymasterThank you for the detailed updates
Unfortunately
navigator.userAgentData.mobile
is not currently supported by Firefox and Safari according to MDN Web DocsChecking the min/max width of the page is indeed a minimally intrusive proxy, although it doesn’t really check whether the participant is using a mobile device—admittedly, user agent sniffing also has its limits, as it can be tweaked by the client
Jeremy
-
AuthorPosts
- You must be logged in to reply to this topic.