Assigning the same embedded variables to a participant in a second survey? | XM Community
Skip to main content

Hi all,
I have a survey where we have 4 different topics we are asking about and within each topic we want participants to answer about randomly selected items within those topics for question 1. For question 2, we want them to answer a question about some of the items they saw in question 1, and additional items with in the topic. Then at a time 2 survey, we want them to answer question 3 about the items they saw in time 1 for question 1 and 2, and additional items they didn't see at time 1.
I've used the following code, which works for the Time 1 survey. What I'd like to know, is how/if I can make sure the randomized assignment of the items to embedded data is carried through to the next participant for any given survey. Can I assign a seed number which would get applied, or link it to the participant id in some way?
//function to get n random non-repeating elements from an array
function getRandom(arr, n) {
var result = new Array(n),
len = arr.length,
taken = new Array(len);
if (n > len)
throw new RangeError("getRandom: more elements taken than available");
while (n--) {
var x = Math.floor(Math.random() * len);
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
}
return result;
}
fruit=['apple' , 'kiwi' , 'banana' , 'grapes' , 'clementine', 'watermelon' , 'cherry' , 'peach']
vegetable= ['carrot', 'corn', 'celery', 'broccoli', 'kale', 'lettuce', 'tomato', 'cauliflower']
animal= ['bear', 'cat', 'dog', 'elephant', 'bird', 'fish', 'hedgehog', 'rabbit']
color= ['red' , 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'purple']

///this is used to generate the word# for testing only - once populated it's deleted
for (i=1; i<=8; i++) {
fruit.push('fruit' + i.toString())
}
for (i=1; i<=8; i++) {
vegetable.push('vegetable' + i.toString())
}
for (i=1; i<=8; i++) {
animal.push('animal' + i.toString())
}
for (i=1; i<=8; i++) {
color.push('color' + i.toString())
}

//gets random items from the above arrays
master_list_fruit = getRandom(fruit, 8)
master_list_vegetable = getRandom(vegetable, 8)
master_list_animal = getRandom(animal, 8)
master_list_color = getRandom(color, 8)

//the loop sets the embedded data variables - I've set up embedded vars fruit1-fruit8 etc.
for (i=1; i<=master_list_fruit.length; i++) {
Qualtrics.SurveyEngine.setEmbeddedData('fruit'+i.toString(), master_list_fruit[i] )
}
for (i=1; i<=master_list_vegetable.length; i++) {
Qualtrics.SurveyEngine.setEmbeddedData('vegetable'+i.toString(), master_list_vegetable[i] )
}
for (i=1; i<=master_list_animal.length; i++) {
Qualtrics.SurveyEngine.setEmbeddedData('animal'+i.toString(), master_list_animal[i] )
}
for (i=1; i<=master_list_color.length; i++) {
Qualtrics.SurveyEngine.setEmbeddedData('color'+i.toString(), master_list_color[i] )
}

The Q1 is a matrix that pulls the embedded data
fruit1
fruit2
fruit3
vegetable1
vegetable2
vegetable3
animal1
animal2
animal3
color1
color2
color3
And then Q2 is a matrix that pulls the embedded data
fruit1
fruit2
fruit4
fruit5
vegetable1
vegetable2
vegetable4
vegetable5
animal1
animal2
animal4
animal5
color1
color2
color4
color5

fruit1
fruit2
fruit6
fruit7
vegetable1
vegetable2
vegetable6
vegetable7
animal1
animal2
animal6
animal7
color1
color2
color6
color7
 
But this requires that the random assignment of items to the embedded data is linked for each participant from survey 1 to survey 2. Any ideas for how to do that?

Leave a Reply