-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
52 lines (44 loc) · 1.85 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<head>
<title>example of netlify-prolific plugin for jspsych</title>
<script src="jspsych.js"></script>
<link href="css/jspsych.css" rel="stylesheet" type="text/css"></link>
<script src="plugins/jspsych-html-keyboard-response.js"></script>
<script src="plugins/jspsych-image-keyboard-response.js"></script>
<script src="experiment.js"></script>
</head>
<body>
<script>
function subbit() {
// add prolific id to jspsych data
let subject_id = jsPsych.data.getURLVariable('PROLIFIC_PID');
jsPsych.data.addProperties({
subject_id: subject_id
});
// get experiment data and send it to netlify
let csvdata = jsPsych.data.get().csv();
let sneakyJSON = document.querySelector("#sneakyjson");
sneakyJSON.textContent = csvdata;
let form = document.querySelector("#dataform");
fetch(
form.getAttribute("action"),
{ method: "post", body: new FormData(form) }
).then(function(res) {
if (res.ok) {
console.log("sent exp data to netlify!");
}
});
// add link back to prolific (remember to change to your code!)
html = "<p>Thanks for your participation!</p><p><a href='https://app.prolific.co/submissions/complete?cc=YOURCODEHERE'>Please click here to return to Prolific</a></p>";
let content_element = document.getElementById('jspsych-content');
content_element.innerHTML = html;
}
</script>
<!-- hidden form used to send data to netlify -->
<form id="dataform" name="submission-data" method="POST" data-netlify="true" hidden>
<textarea name="jspsych-data" id="sneakyjson">this text will automatically be replaced with your data</textarea></label>
<button type="submit">Send</button>
</form>
</body>
</html>