How to conditionally end an online experiment in PsychoPy with Pavlovia surveys

Hello everyone,

I’m working on an online PsychoPy experiment including Pavlovia surveys. I’ve included one survey for participant screening. My goal is to ensure that participants who do not meet the inclusion criteria (e.g., age <18 years) are shown a message like “Unfortunately, you do not meet the inclusion criteria. You can now close the browser window,” and are prevented from continuing to the main experiment.

Here’s the setup:
In the screening questionnaire, there is one critical question with two response options:

  • “<18 years”
  • “>18 years”
    If participants select “<18 years”, I want them to be stopped entirely and not proceed to the actual experiment. If they select the other option, they will proceed to the actual experiment.

I’ve tried implementing this following the approach from Wakefield’s video (https://www.youtube.com/watch?v=rPXuHs5ykS4), but I’ve encountered a problem:
While I can direct participants to the correct survey page that says they are ineligible, the navigation buttons cannot be disabled for just that page. This means participants can still click “Proceed” and move on to the main PsychoPy experiment, even though they’ve been told they’re not eligible. The logic function works quite well, but how can I stop the experiment from continuing after the Pavlovia survey?

Can you tell me, how to implement a solution where ineligible participants are completely stopped from proceeding after a Pavolovia survey? Ideally, I’d like to disable or remove the “Proceed” button on the ineligibility page or find another way to terminate the experiment at this stage.

Thank you in advance!

Hello

I had a similar problem. The participants have to agree to the GDPR, otherwise they cannot participate. My survey is included in a PsychoPy experiment, so I get the relevant information from the survey with a code component. The survey component is called demo.

Begin Experiment

VPn = " ";
VPCode = " ";

zuStimmung = " ";

Begin routine

VPn = expInfo["participant"];
surveyResp = demo.getResponse();
VPCode = surveyResp["VP-Code"];

zuStimmung = surveyResp["ZustimmungDatenschutz"];

if ((zuStimmung === "FALSE")) {
    quitPsychoJS('Vielen Dank für Ihr Interesse', false);
    psychoJS.setRedirectUrls("https://www.uni-muenster.de/Psychologie/", "https://www.uni-muenster.de/Psychologie/");
}

If you are only using a survey, create a logical expression on the Survey Logic tab and close the survey.

grafik is the survey “equivalent”.

Best wishes Jens

Thanks, Jens! Your second suggestion is, what I tried before, but it doesn’t work in my case. The logic itself works fine — when participants select a certain condition (e.g., they do not meet the inclusion criteria), the survey correctly terminates as expected. However, the subsequent routine in PsychoPy still starts, which I want to avoid. In other words, while the survey closes based on the logic, the experiment continues running afterward. My goal is to completely stop the experiment at this point if participants do not meet the criteria.

So, I think your second suggestion should be the right approach. I tried to adapt your code to my experiment, but it didn’t work. Could you please clarify where exactly to include this code component (in the subsequent routine in PsychoPy?) and how to correctly access the corresponding response from the survey results file?

Thank you for your help!

Hello @Angelika

Here is my solution to this problem. Note that I don’t check the age of a participant, but whether they agree to the GDPR statement.

Here are the two routines

demo is in PsychoPy the embedded survey, getDemo is the routine to get the values from the demo survey. It contains a JavaScript only code component.

In Begin Experiment I initialize a couple of variables.

VPn = " ";
VPCode = " ";
zuStimmung = " ";

In Begin Routine I query the values from the embedded survey

VPn = expInfo["participant"];
surveyResp = demo.getResponse();
VPCode = surveyResp["VP-Code"];

zuStimmung = surveyResp["ZustimmungDatenschutz"];

if ((zuStimmung === "FALSE")) {
    quitPsychoJS('Vielen Dank für Ihr Interesse', false);
    psychoJS.setRedirectUrls("https://www.uni-muenster.de/Psychologie/", "https://www.uni-muenster.de/Psychologie/");
}

I check the value of zuStimmung and abort the experiment if its value is FALSE. Upon exiting, I redirected the participant to the institute’s website regardless of whether the experiment was completed or not completed.

I hope that helps.

Best wishes Jens

Thanks again!
It finally works! :slight_smile: But only as long as you redirect to another website. If you don’t, the entire experiment restarts after being aborted. I can’t understand why, because normally using quitPsychoJS should end the experiment.

Anyway, since I’m redirecting to another website, your solution works perfectly for me. Awesome!

Hello Angelika

I never tried this approach without a redirect to a website.

I glad that it worked.

Best wishes Jens