title: Firestore cloud doesn't save data from all users (js)
body: <p>I have programmed an experiment using js and deploy it through firebase.</p>
  <p>However I have noticed that the data of some participants is not stored, despite. I have only run three participants, i.e. 3 users on the website at the same time so I doubt it is due to it being overwhelmed and according to the documentation this shouldn't be a problem.</p>
  <p>I know the page itself is working as the users all get redirected to another URL afterwards.</p>
  <p>My concern then was that the save function was not executed quickly enough so I have included a minimum trial duration. Does anyone have any suggestions on how to solve this?</p>
  <p>I would appreciate any advice on this.</p>
  <p>Thank you!</p>
  <pre><code>function saveData(data){
        console.log(&quot;trying to save&quot;);
        const db = firebase.firestore();
        var data = JSON.parse(data);
        var namedData = {};
        data.forEach(function(q) {  
        //console.log(q.internal_node_id) 
        if(q.hasOwnProperty(&quot;responses&quot;))
        {
          q.responses = JSON.parse(q.responses);
        }
        namedData[q.internal_node_id] = q; 
      })
        //db.collection(&quot;user&quot;).doc(subject_id).set(namedData)
        db.collection(&quot;user&quot;).doc(subject_id).set(namedData)
          .then(function() {
            console.log(&quot;data saved&quot;)
          })
      }        
  var saving = {
        type: 'html-keyboard-response',
        stimulus: &quot;&lt;p style='font-size: 24px;'&gt;You have reached the end of this experiment. &lt;br&gt;&lt;br&gt;Thank you for participating! &lt;br&gt;&lt;br&gt; Please wait to be redirected to the next page. The data is saving. Do not press any key.&quot;,
        response_ends_trial:false,
        trial_duration: 5000,
        on_start: function() {(saveData(jsPsych.data.get().json()));
                },
      };
       // on_finish: function() {(saveData(jsPsych.data.get().json()));
  
  
      timeline.push(saving)
      
      var end = {
        type: 'html-keyboard-response',
        stimulus: &quot;&lt;p style='font-size: 24px;'&gt;Please press any key to be redirected to Prolific.&lt;/p&gt;&quot;,
        response_ends_trial:true,
        on_finish: function() {(window.location.replace(&quot;https://samplepagehere&quot;))},
      };
  </code></pre>