Wilbert's website at SocSci

> jsPsych> 4 Participants

jspsych/04participants.html 2020-07-15

Programming in JavaScript with jsPsych, Participants

You have now been able to run an experiment and save your data. You may have noticed that the participant number (ppn) is zero each time you run the experiment. This is quite useful for testing (we usually reserve the ppn range 0-9 for testing in all experiments, so that we can keep running tests even during the data collection phase of the experiments. But for data collection we need a ppn that is different for each participant. We describe a few options for doing this:

Typing the participant number

The classic way is to let a participant type their participant number at the start of the experiment. In jsPsych this means that we add a trial, which consists of a single question of which we read the response into the ppn variable, which will be used later. Add the following trial:

ppn_form = {
	type: 'survey-text',
	questions: [{prompt: "Please enter your participant number.", name: "ppn"}],
	on_finish: function(data){
		ppn = JSON.parse(data['responses'])['ppn'] // get ppn from trial data
	}
}

We now add this ppn_form trial to the trial timeline and change the saveData call to use the ppn variable. Change

jsPsych.init({
	timeline: [hello],
	on_trial_finish: function(data){ saveData("7A9AEEC1", 2, data) },
})

into

jsPsych.init({
	timeline: [ppn_form, hello],
	on_trial_finish: function(data){ saveData("7A9AEEC1", ppn, data) },
})

Note that ppn_form must be the very first trial in the timeline, otherwise an error ReferenceError: ppn is not defined will appear in the developer console and the experiment will halt.

Email invitation

To invite people to your experiment. It will first have to have a publicly available adres, a URL. Lets for the moment assume the URL is https://exp.socsci.ru.nl/demo. If you send email invitations to your participants your would normally include this url. Instead of simply including the url, we now append ?ppn=123, where 123 is the participant number for this particular invitation, making the entire invitation url: https://exp.socsci.ru.nl/demo?ppn=123

We now change the experiment to use this ppn. Change

jsPsych.init({
	timeline: [hello],
	on_trial_finish: function(data){ saveData("7A9AEEC1", 2, data) },
})

into

let ppn = jsPsych.data.urlVariables()['ppn']
jsPsych.init({
	timeline: [hello],
	on_trial_finish: function(data){ saveData("7A9AEEC1", ppn, data) },
})

Do note that whenever you do not include the ppn=123 part of your url, you will get the value undefined for ppn, which is a perfectly valid value. If you would include ppn=, you would get the empty string as ppn, which is not a valid value, and which will give your participants an error popup.

Panel systems

Sona

Panel integration of jsPsych experiments is similar to how Sona links to Limesurvey. In the Sona Study URL we now have to include ppn=%SURVEY_CODE%, making the entire Study URL: https://exp.socsci.ru.nl/demo?ppn=%SURVEY_CODE%

The changes in the experiment are the same as for the email invitations.

If additionally you want to award credits, you will have to return to the sona web page after the study is completed. Add the following line to your experiment (using your value for experiment_id and credit_token).

let ppn = jsPsych.data.urlVariables()['ppn']
jsPsych.init({
	timeline: [hello],
	on_finish: function(data){ 
		window.location.assign("https://radboud.sona-systems.com/webstudy_credit.aspx?experiment_id=123&credit_token=4e48f9b638a&survey_code="+ppn)
	},
})

Prolific

For prolific things are very similar to how it is for Sona. You should first tick the option would you like to include special parameters such as PARTICIPANT_ID in your study url? and then the Study URL becomes: https://exp.socsci.ru.nl/demo?ppn={{%PROLIFIC_PID%}}

If you also want your participants to report to Prolific that they have completed their experiment, you should change the url at the bottom of the experiment, where participants are send after completion to ( using your value for the completion code):

https://prolific.ac/submissions/complete?cc=GE8BYGCF

Chapter 3, Retrieving data - previous — next - Appendix 1 counting