JavaScript for Reaction Times (trouble producing full string of RTs in Embedded Data)

bmillsbmills ConnecticutCommunity Member Qubie ✭

JavaScript for Reaction Times (trouble producing full string of RTs in Embedded Data)

Hi there,

I'm trying to implement javascript to calculate reaction times for a set of randomized questions (within a randomized block) and am having trouble getting the full string of reaction times to appear in the survey's Embedded Data. I've found some really useful code on here and have modified slightly to fit my project. Here's what I have so far:

Qualtrics.SurveyEngine.addOnload(function()
{
var starttime = new Date().getTime();
$('NextButton').hide();

this.questionclick = function(event,element){
    if (element.type == 'radio') {
            var endtime = new Date().getTime();
            var RT = (endtime - starttime)/1000;
            var EmData = Qualtrics.SurveyEngine.getEmbeddedData('reactiontime');
            var Holder = [];
        if (EmData == null){
            Holder += "RT1:";
            Holder += RT;
            Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', Holder);
        }
        if (EmData != null){    
            Holder += EmData;
            Holder +=  ", ";
            Holder += "RT1:";
            Holder += RT;
            Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', Holder);
        }
            $('NextButton').click();           
        }
    }
});

The Holder text (e.g., "RT1") is modified for each question, so question 2 is RT2 and so on.

This DOES produce embedded data that I can view at the end of my survey, and each RT is nicely labelled so that I can tell which question it came from. The problem that I'm having is that I am not reliably getting the RT data for every question -- using a practice set of 9 questions, I am ending up with somewhere between 3-5 RTs in my embedded data (e.g., reactiontime RT4: 3.145, RT7: 3.148, RT9: 3.331, RT6: 2.923). I can't figure out why the remaining questions are not mapping into the embedded data field correctly. Also, note that the questions that DO appear in the embedded data change each time I trial the questions, so it doesn't appear to be an issue with specific questions, but rather the final string of data that's produced.

Does anyone have any suggestions as to how I can correct this so that ALL reaction times appear in my embedded data?

Thanks in advance!

Answers

  • rondevrondev Community Member - Trial User Guru ✭✭
    edited May 17

    Hi @bmills,

    This is a good code. I tested this with all situations i.e taking survey very fast, slow, but always I got all the data. Please check if your setup is correct, also check is there any error message in the console.

  • bmillsbmills ConnecticutCommunity Member Qubie ✭

    Hi @rondev --

    Thanks for your response! I tried creating a new survey and testing the code in there and found that it worked well. I did some more digging and it appears that the Autoadvance on Pages selection is the culprit! Any ideas on how to override that for this particular block of questions? If not, I think we can figure out a way to work around it...we just have a very long survey so adding JS to every question would be less than ideal.

    Thanks!

Sign In to Comment