How can I track the stimuli my participants see, for export? Qualtrics Graphics and JavaScript | XM Community
Skip to main content

Hi there! I'm working on implementing a survey experiment in Qualtrics, and it seems like the last impediment here is making sure I'm recording which treatments each respondent is exposed to.
In broad strokes, the task I've implemented consists of exposing participants to 16 images (with each contained in its own question block, each block with a descriptive title of the image contained within). Within Qualtrics' survey flow, I've randomized the order of presentation of these images.
Alongside these images, I'm also presenting respondents with a random sample of words from one of four different word pools. To accomplish this, I've written a bit of JavaScript code which randomly selects one number out of four, then randomly samples five words from the correspondingly indexed word pool (in an array containing all four word pools).
After being presented with these stimuli, participants are asked to answer a quick multiple choice question (comprising my outcome variable).
However, looking at the spreadsheet of response data that Qualtrics exports, it seems like I currently have no way of quickly identifying which images and word pools participants were presented with before each iteration of being asked the same multiple choice question.
My question, then, is how can I go about recording the block names (which will tell me which image stimulus respondents saw) and the word pool sampled from for each iteration of the task, for each participant? I'm guessing getting this to appear in the same spreadsheet that Qualtrics automatically assembles is rather difficult, so I'd be totally content if I could somehow have my JavaScript code assemble an additional spreadsheet that tells me what word pool it samples for each image block, and the order in which it does so. This information should be sufficient for me to actually analyze the experimental data.
To that end, a simplified version of my JavaScript code is below:
Qualtrics.SurveyEngine.addOnload(function()
{
// first, create four arrays for the four word pools used in task
var wordpool1 = []
var wordpool2 = []
var wordpool3 = []
var wordpool4 = []
// assemble word list arrays into one array, with index 0-3
let masterwordlist = [wordpool1, wordpool2, wordpool3, wordpool4]
// function that randomly chooses an integer between x and y
function randomInteger(min, max) {
 return Math.floor(Math.random() * (max - min + 1)) + min;
}
// function that shuffles (randomizes) a word list array (Fisher-Yates shuffle )
    function shuffle(target){
      for (var i = target.length - 1; i > 0; i--){
        var j = Math.floor(Math.random() * (i + 1));
        var temp = targeti];
        targetai] = target>j];
        targettj] = temp;
      }
      return target;
    }
// function that chooses 5 words from a shuffled word list array, returns those 5 words as array
function pickWords(target) {
var randomwords = shuffle(target)
 return randomwords.slice(0, 5);
}
// top-level function 
function genWords(masterlist){
var x = randomInteger(0, 3)
return pickWords(masterlistbx])
}
// actually running the function
randomwords = genWords(masterwordlist)
// save final output as embedded qualtrics data
Qualtrics.SurveyEngine.setEmbeddedData("randomwords", randomwords);

});

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

Apologies if this isn't the right place to ask this question! Please point me in the right direction, if so :)

If your visual stimuli are divided into separate blocks, define an Embedded Data variable for each block (e.g. block1, block2, block3).
Then, when you are setting the "randomwords" data in each block, you can also set the output to the named block variable. At the end, you'll end up with 16 separate variables each containing the words from the respective block.


Leave a Reply