Watts-Lab / surveys

Library of surveys for deliberation experiments
MIT License
3 stars 4 forks source link

Record order of questions that are randomized #170

Open JamesPHoughton opened 9 months ago

JamesPHoughton commented 9 months ago

When we randomize questions on the page, we want to know the order that those questions appear to the user, and save this with the response. Recording and saving with the state might help with: https://github.com/Watts-Lab/surveys/issues/151

JamesPHoughton commented 9 months ago

Copilot suggests this:

let questionOrder = [];

survey.onAfterRenderQuestion.add(function(survey, options) {
    questionOrder.push(options.question.name);
});

// After the survey is completed, you can see the order of questions
survey.onComplete.add(function(result) {
    console.log(questionOrder);
});

Strictly speaking, this only records the chronological order they were displayed in, not the visual order on the page