I am using js and jsPsych to code an experiment.
At the end of the task I want to save the data to Firebase Firestore and then redirect to a location. However, currently no data is being saved when I include the window.location.replace. It works fine without the redirection. But I need both. Any advice would be much appreciated.
jsPsych.init({
timeline: timeline,
preload_images: [
on_finish: function() {(saveData(jsPsych.data.get().json()));
(window.location.replace("https://url.com"));
},
});
function saveData(data){
console.log("trying to save");
const db = firebase.firestore();
var data = JSON.parse(data);
var namedData = {};
data.forEach(function(q) {?
//console.log(q.internal_node_id)?
if(q.hasOwnProperty("responses"))
{
q.responses = JSON.parse(q.responses);
}
namedData[q.internal_node_id] = q;?
})
//db.collection("user").doc(subject_id).set(namedData)
db.collection("user").doc(subject_id).set(namedData)
.then(function() {
console.log("data saved")
})
}
Many thanks!