psychopy.org | Reference | Downloads | Github

Help with redirect to SONA at end of experiment

URL of experiment: https://run.pavlovia.org/nichdima/moral_imagination_MVP

Description of the problem: I am new to Pavlovia and JsPsych (and programming in general!), so I’m struggling with something I hope you all can help me solve. I’m using the pavlovia plug in and following what has been outlined there to try to redirect participants to a completion link at the end of the study. However, I’m not entirely sure how to get them to the page. Here is my code:

var surveyCode = jsPsych.data.getURLVariable('survey_code');

var finishURL = 'https://sona-systems.com/otherinfohere&survey_code=' + surveyCode;

/* finish connection with pavlovia.org */
var pavlovia_finish = {
  type: "pavlovia",
  command: "finish",
  participantId: surveyCode,
    // Thomas Pronk; your filter function here
    dataFilter: function(data) {
          // Printing the data received from jsPsych.data.get().csv(); a CSV data structure
          console.log(data);
          // You can also access the data directly, for instance getting it as JSON
          console.log(jsPsych.data.get().csv());
          // Return whatever data you'd like to store
          return data;
      },
      // Thomas Pronk; call this function when we're done with the experiment and data reception has been confirmed by Pavlovia
      completedCallback: function() {
        alert('Clicking OKAY will redirect you.<a href="' +finishURL+ '" target="blank">');
      }

Hey! Try window.location.replace. See this page: javascript - Difference between window.location.assign() and window.location.replace() - Stack Overflow

1 Like

In case it is helpful for anyone else, here is my modified code:

var pavlovia_finish = {
  type: "pavlovia",
  command: "finish",
  participantId: surveyCode,
    // Thomas Pronk; your filter function here
    dataFilter: function(data) {
          // Printing the data received from jsPsych.data.get().csv(); a CSV data structure
          console.log(data);
          // You can also access the data directly, for instance getting it as JSON
          console.log(jsPsych.data.get().csv());
          // Return whatever data you'd like to store
          return data;
      },
      // Thomas Pronk; call this function when we're done with the experiment and data reception has been confirmed by Pavlovia
      completedCallback: function() {
        window.location.replace(finishURL);  
      }
  };
tl.push(pavlovia_finish);
1 Like

I took the liberty of marking your modified code as the solution. But just to check: it works right?

Yes!

1 Like