Embedded data, randomization and Javascript : How to record the presentation order each time ? | XM Community
Skip to main content

Hi,
I carry out a study in which I present different sentences (one per page). I inserted a first name randomly in each sentence. 
I created one descriptive text question and add this code in Javascript (thanks to the contributor who helped me!).
Qualtrics.SurveyEngine.addOnReady(function()
{
var names = "Jennifer", "Jessica", "Amanda", "Ashley", "Sarah", "Stephanie", "Melissa", "Nicole"];
var copy = names.slice();
var cnt=1;
while( copy.length )
{
var name = copy.splice( Math.floor(Math.random()*copy.length), 1 );
console.log(name)
Qualtrics.SurveyEngine.addEmbeddedData("name"+cnt, name);
cnt+=1
}
jQuery('#Wrapper').css('visibility','hidden');
jQuery('#Wrapper').css('opacity','0');
jQuery('#NextButton').click();
});

My problem is that i have to recorder the order that was presented to each participant. How can I do that ?
Ideally, the order should be recorded in the response data.

Thank you very much for your help and have a good day !

Create an embedded data "NameOrder" and update the code as below:
Qualtrics.SurveyEngine.addOnReady(function()
{
var names = ["Jennifer", "Jessica", "Amanda", "Ashley", "Sarah", "Stephanie", "Melissa", "Nicole"];
var copy = names.slice();
var cnt=1;
var arr = [];
while( copy.length )
{
var name = copy.splice( Math.floor(Math.random()*copy.length), 1 );
console.log(name)
Qualtrics.SurveyEngine.addEmbeddedData("name"+cnt, name);
arr.push(name);
cnt+=1
}
Qualtrics.SurveyEngine.addEmbeddedData("NameOrder", arr.toString());
jQuery('#Wrapper').css('visibility','hidden');
jQuery('#Wrapper').css('opacity','0');
jQuery('#NextButton').click();
});



Thank you very much, it works perfectly.
Your contributions are always very helpful!


I have a similar question. In my survey, there are 2 conditions (A and 😎. Either condition includes one picture and several questions. I want to present the 2 conditions in the order of either A, B or B, A and record the order in the data. How can I do it? Thanks


During export, you have the option to get the display order. Read more here.


https://www.qualtrics.com/community/discussion/comment/34253#Comment_34253You can do it using randomizer inside survey flow to first save order "AB" or "BA" in embedded data and then use branch logic based on embedded data to show two condition in order A,B or B,A.


Leave a Reply