Home > Software design >  (how) can I tell my JavaScript to append a variable/column to the data Qualtrics exports?
(how) can I tell my JavaScript to append a variable/column to the data Qualtrics exports?

Time:12-03

I've implemented a task in Qualtrics that randomly selects a number between 0 and 3, and then selects a corresponding word pool to sample 5 words from. To be able to analyze these data, though, I need to know which 5 words (or at minimum, the index number or name of the word pool being sampled from) is presented to each respondent. Is there a way to implement the recording of this information within JavaScript? Ideally this information would show up when I use Qualtrics' native "export" options, but if I have to somehow create a second spreadsheet with this treatment data, that works just fine as well.

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 = target[i];

        target[i] = target[j];

        target[j] = 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(masterlist[x])

}

// actually running the function

randomwords = genWords(masterwordlist)

// save final output as embedded qualtrics data

Qualtrics.SurveyEngine.setEmbeddedData("randomwords", randomwords);

Is there a way I can have this code record (within Qualtrics or otherwise) which values var x or var randomwords take on?

EDIT: I found another answer on here which may be relevant. According to this answer, though, it looks like I have all the code needed to record my variable selection; do I simply need to set embedded data within the survey flow, as well? See here: Is it possible to save a variable from javascript to the qualtrics dataset?

CodePudding user response:

Yes, you need to define the embedded data field randomwords in the survey flow.

  • Related