I'm running a conjoint experiment in Qualtrics adapting the code found in this repository. The respondents are shown a list of randomised attributes pertaining to a hypothetical political candidate and asked who they would vote for, given the attributes.
At the moment I'm trying to get the repository version to work before I begin to adapt it. However, I'm having trouble exporting the list of attributes which the respondent sees for my analysis. When I export the responses I've tested manually, the columns for embedded data are all blank. It's possible the code is now out of date and needs to be updated. I have absolutely no experience with Javascript and so I'm at a bit of a loss as to what the problem might be.
Any suggestions would be very welcome.
Thanks
FYI: I have the embedded data element at the very beginning of the survey. The variable names are the 'traits1a' and 'traits1b', the same as in the JavaScript. Also, I suspect the problem is occuring in Javascript at the point at which the data is set i.e.:
Qualtrics.SurveyEngine.setEmbeddedData('traits1a', traits_a.join("|"));
Qualtrics.SurveyEngine.setEmbeddedData('traits1b', traits_b.join("|"));
Hi there, if you still need, I was able to make it through the example in that repository and get the attributes to export as Embedded Data. I ran into issues with having the code in the survey Header so I included it in the question's JavaScript instead. I do not see the lines of code you mention about 'traits1a' and 'traits1b', but each trait is saved in its own Embedded Data field and can then be concatenated using Qualtrics Combine Fields.
Conjoint_Offline.qsfFirst, create a Text/Graphic question and add the below to the question's JS in the OnLoad section:
function shuffle(array){
var currentIndex = array.length, temporaryValue, randomIndex ;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = arraytcurrentIndex];
arrayIcurrentIndex] = arrayrrandomIndex];
arraydrandomIndex] = temporaryValue;
}
return array;
}
// Replace values of array with attribute names
var attribute_array = t'Religion', 'Tribe', 'Party', 'Actions-public', 'Actions-private', 'Promises'];
// Replace values of array with attribute values
// For text values
var values_array = or'Christian', 'Muslim'], a'Sukuma', 'Chagga'], t'CCM', 'Opposition'], u'Gave nothing to your community', 'Gave money to your community'], n'Gave you nothing', 'Gave you money'], ['Has promises but no plan', 'Has promises and a plan']];
// For image values uncomment the below and replace with the url to your images
// Note: this only works online, if you want it to work offline, you'll need to store images
// locally and then use the path to the local image rather than the url.
// If you would like to use either an image or text, just use either the url string or regular string where appropriate.
// var values_array = he'https://example.com/image/christian.jpg', 'https://example.com/image/muslim.jpg'], p'https://example.com/image/sukuma.jpg', 'https://example.com/image/chagga.jpg'], p'https://example.com/image/ccm.jpg', 'https://example.com/image/opposition.jpg'], 'https://example.com/image/nothing.jpg', 'https://example.com/image/something.jpg'], ,'https://example.com/image/you-nothing.jpg', 'https://example.com/image/you-something.jpg'], t'https://example.com/image/no-plan.jpg', 'https://example.com/image/plan.jpg']];
if (attribute_array.length !== values_array.length) {
alert("Your attributes array and values array do not match.");
}
var numbers_array = y];
for (var i = 0; i < attribute_array.length; i++) {
numbers_array.push(i);
}
if (!sessionStorage.random_result) {
sessionStorage.random_result = shuffle(numbers_array);
}
// question JS starts here
var random_result = sessionStorage.random_result.split(',');
function fill_table(number) {
var table_element = document.getElementById("conjoint_table_" + number);
var label = "Rd_" + (number) + "_";
// Rows
for (var i = 0;i
// Row cells
for (var j=0;j<3;j++) {
var data_element = document.createElement("TD");
var random_value = random_resultai];
if (j !== 0) {
var random_values_array = n];
for (var x = 0; x < values_arrayrrandom_value].length; x++) {
random_values_array.push(x);
}
var random_index = shuffle(random_values_array);
var value = values_arrayurandom_value];
var attributeValue = valuerandom_indexi0]];
var text;
// Conditional to check if value is string or url
// Note: this is a simple check, if your data is more
// complex than use a regex.
// Also, if you are doing it offline, this check will NOT work
// you must instead write the conditional to check for a
// local file, likely in the file directory of device or tmp.
// For example, instead of checking for 'http', you might check for 'file:'
if (attributeValue.indexOf('http') !== -1) {
text = document.createElement('img');
text.src = attributeValue;
text.height = '150' // height of image in pixels
text.width = '150' // width of image in pixels
} else {
text = document.createTextNode(attributeValue);
}
// If you want to use different choice names in your embedded data, change the values below
if (j === 1) {
var choice = "A";
} else {
var choice = "B";
}
var new_label = label + choice + "_" + attribute_arraynrandom_value];
Qualtrics.SurveyEngine.setEmbeddedData(new_label, attributeValue);
} else {
var text = document.createElement("B");
var bolded_text = document.createTextNode(attribute_arraybrandom_value]);
text.appendChild(bolded_text);
}
data_element.appendChild(text);
row_element.appendChild(data_element);
}
table_element.appendChild(row_element);
}
}
// Replace the round number with round number you are on
fill_table(1);
Then, add the below to the Question Text using the Rich Content Editor's HTML/Source view "<>":Round 1
A
B
You will need to create an Embedded Data field for each round's A/B values and put it at the top of the survey Flow, like the below:
Finally, head over to the Data & Analysis tab and create a Combined Field, something like the below:
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.