Wilbert's website at SocSci

> jsPsych> 2 Saving data

jspsych/02saving.html 2020-04-02

Programming in JavaScript with jsPsych, Saving your data

Now that we have a fully working experiment in jsPsych, we can save the data. Saving data is not part of jsPsych. We are going to save the data in the web browser. After the experiment is finished you can retrieve your data with the same browser on the same computer.


Now visit the Radcloud Mini experiment page. Log in with youw u-number (this may be a student number starting with an s, or and employee number starting with a u) and make a new experiment. Just entering a name will do.

As long as there is no data in the experiment, you can delete it. Deleting experiments with data is a feature that will be added later on. Note that it is your own responsibility to delete the data.

Note the 8 digit api key of the experiment. You will need it later.


Download the following file:

Put this files in the experiment directory, that is, the directory that also contains index.html your experiment file.

Altering the experiment

First we must let the browser know that we are going to use this data handler. Therefore we add the following line to the head section of the experiment file (between <head> and </head>:

<script src="datahandler.js"></script>
and we add the follwing line just above timeline: [hello],
on_trial_finish: function(data){ saveData("FFFFFFFF", 0, data) } ,

The whole experiment now looks like:

<!DOCTYPE html>
		<meta charset="UTF-8">
		<script src="jspsych-6.1.0/jspsych.js"></script>
		<script src="jspsych-6.1.0/plugins/jspsych-html-keyboard-response.js"></script>
		<script src="datahandler.js"></script>
		<link rel="stylesheet" href="jspsych-6.1.0/css/jspsych.css">
		<link rel="icon" href="data:;base64,iVBORw0KGgo=">
	hello = {
		type: 'html-keyboard-response',
		stimulus: 'Hello world',
		choices: jsPsych.NO_KEYS,
		trial_duration: 1000,
		timeline: [hello],
		on_trial_finish: function(data){ saveData("7A9AEEC1", 2, data) },

Before running the experiment again please press F12. It will show your browsers developer tools at the bottom or right side. Please click Console. Now load or reload (F5) your experiment. You will see Hello World again for a few seconds. After that the developer console will show someting like: Server answer: LOG: success saving data: {"rt":null,"stimulus":"Hello world","key_press":null.... That is good. Your data was saved.

Please note that data is saved both on the server and on the client computer

Chapter 1, Hello world - previous — next - Chapter 3, Retrieving data