On Qualtrics, how to save embedded data with javascript (given that qualtrics has recently been updated and an old SO solution no longer works)

余生长醉 提交于 2019-12-04 05:45:45

问题


A few months ago I used the excellent advice over here to create a survey in Qualtrics with some javascript code that saved people's responses (given by moving a slider) as embedded data. It all hinges on being able to call some functions when the "Next" button is clicked, as is found under $('NextButton').onclick = function (event) in the above link.

I wanted to reuse that survey this weekend, and found that the data was no longer being saved. After fiddling around a bit, I realised that currently, any such function will now only be run the first time the "next" button is clicked, and not on any subsequent time. In other words, precisely the same javascript will either work or do nothing depending on whether it happens to be the first time the next button is clicked.

I mailed Qualtrics asking for advice, and their support person mailed back with the following:

The old application that ran our surveys would reload the page each time you went to a new page in the survey. The current application that runs our surveys is a one page app and going to the next page in a survey does not refresh that entire page, it just presents a different section.

I couldn't find anything on the Qualtrics website giving more information about the aforementioned update, or indicating whether there's a new CSS selector that could be used to select the currently-displayed "next" button, replacing $("NextButton"), and I have no idea how to reverse engineer a Qualtrics survey web page to work it out for myself.

Can anyone suggest how the code in the linked answer above might be altered to work on the updated Qualtrics platform? Or can anyone confirm whether their old code still works, in which case I'm mis-identifying what the problem is.

I have insufficient reputation to comment on the above-linked solution to point out this issue, but perhaps someone else could do so. I'll update this if I get any more information from Qualtrics support.


回答1:


Qualtrics uses two survey engines: the older SE and the newer JFE. Qualtrics Support was referring to JFE. You can force Qualtrics to use SE by adding the parameter Q_JFE=0 to your survey link. That might be a quick fix.

That said, adding an event listener to the NextButton has never worked reliably with either SE or JFE. Qualtrics has its own event listeners on the Next Button that interfere. The most reliable method is to use JavaScript to hide the NextButton, then add your own button that performs any process you need, then at the end clicks NextButton. See example here.




回答2:


I haven't tried T. Gibbon's Q_JFE=0 suggestion above, and the suggestion to hide the Next button didn't work for me (though it's possible this was just because I did it wrong - perhaps someone could comment if it worked for them).

When I mailed Qualtrics, their suggestion was to add an event listener as follows, and then remove it before applying another.

document.getElementById('NextButton').addEventListener(function (event) {
doStuff();
});

However, since I'm just a psychologist who wants to get data quickly rather than a javascript programmer, I wasn't sure just how to go about 'removing an event listener', and decided to try what I thought was a simpler solution, in that it doesn't rely on having some functions run when the 'next' button is clicked.

For each question that contains a slider whose data I want to save (I had just one such question per page), I included the following, to save the ID for that particular question as embedded data. Each question's ID is saved with a unique tag ('q1ID' in the following). I had one such question per page.

Qualtrics.SurveyEngine.setEmbeddedData('q1ID', this.getQuestionInfo().QuestionID);

Then once all the slider-type questions had been presented, on the following page I included this code:

Qualtrics.SurveyEngine.addOnload(function()
{
    var tags = ['q1','q2', 'q3'];

    var pipedStrings = {'QID356':'${q://QID356/TotalSum}',
        'QID357':'${q://QID357/TotalSum}',
        'QID358':'${q://QID358/TotalSum}'};

    tags.forEach(function(tag) {
        var qID = Qualtrics.SurveyEngine.getEmbeddedData(tag + 'ID');
        var response = pipedStrings[qID];
        Qualtrics.SurveyEngine.setEmbeddedData(tag, response);

    });
});

Initially, I'd tried what I thought was more sensible:

tags.forEach(function(tag) {
        var qID = Qualtrics.SurveyEngine.getEmbeddedData(tag + 'ID');
        var response = '${q://' + qID + '/TotalSum}';
        Qualtrics.SurveyEngine.setEmbeddedData(tag, response);

    });

But as pointed out here, Qualtrics won't allow you to fetch data by concatenating a variable into a string like this. Consequently, even though it seems a ridiculously roundabout what to do it, I created the pipedStrings object that has a list of all the question IDs I needed (which I found by exporting the survey to a text file and searching for my question tags).

This allowed me to save the responses to slider questions as embedded data, with the keys listed in tags. If anyone has a simpler approach, avoiding have to create the dictionary of pre-formatted strings, please do comment.



来源:https://stackoverflow.com/questions/38961290/on-qualtrics-how-to-save-embedded-data-with-javascript-given-that-qualtrics-ha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!