| Reference | Downloads | Github

Recieving subject id automatically

My subjects are asked to perform a task on my website and then they should fill a survey.
The hardest issue here is to synchronize the data, collected by my task (not related to psychopy), and the survey.
To perform an automatic data sync (by user id) I need to write a user’s id (that he receives on my website) to the survey database.

I’m wondering whether a psychopy survey can get subject id (created by my website) as a variable.



We will be supporting the use of variables in URL requests, yes, but that isn’t implemented at the moment. Note that this is just a proof of principle so far, with serious development due to begin soon.

Same issue here, don’t want to rely on participants typing in their correct ID :wink:

I’ve found a workaround that I want to share here, so people might be able to test and improve it. Please mind that I have not tested this solution under “real” conditions yet. However, so far it’s been working for me :slight_smile:

  1. You can get attributes from the URL as described here. Let’s say your URL is my_experiment.html, then you could add each participant’s ID by adding my_experiment.html/?id="[insert ID]"

  2. Now you need to add a function to the index.html file to read the ID from the URL. There are many ways to do this, I’ve used this suggestion, because it was the simplest I came across.
    Add the function at the beginning of the script where all the other functions are defined. Since I will only read attribute “id” from the URL, I’ve adjusted the function

	function getURLparameter() {
    		return decodeURIComponent((new RegExp('[?|&]' + 'id' + '=' + '([^&;]+?)(&|#|;|$)').exec(||[,""])[1].replace(/\+/g, '%20'))||null;
  1. Also in the index.html file, add

where this is done for all the other functions.

  1. Now adjust the gui. In my experiment, they shouldn’t have to enter any information themselves, so I simply instruct them to click OK.

In function run() in the index.html file, change expInfo to an empty dictionary:

expInfo = {};

In function updateInfo(), add

expInfo['participant'] = getURLparameter();

You should use the key ‘participant’ cause that’s how it is defined in data.js (otherwise you’d have to change that too I guess).

  1. In the gui.js script, you’ll see a line saying
<p class="validateTips">Fields marked with an asterisk (*) are required.</p>';

You could change this to say something like

'<p class="validateTips">Click "OK" to start task.</p>';		

Hope it helps and I didn’t forget to note any step.

1 Like