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 Wizard ✭✭✭✭✭
    edited May 2019

    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!

  • GioDiGioDi LisbonCommunity Member Qubie ✭

    Hello @rondev and @bmills,

    I am creating a survey which includes multiple blocks containing several questions, all presented on a separate page. I would like to record the time from page onset to next page button press, for each of my questions. I have tried using the code provided above, but I only get one RT in the results. I am new to both Qualtrics and Javascript, so this is probably due to the way I set up my survey. In the survey flow, I have added an embedded data before the block of interest. I have tried inserting the Javascript in just the first question in the block, as well as in all of the questions, but I still only get one RT. Does the code have to be placed somewhere else, in order for it to apply to all of the questions within the block? Also, the reaction time I get in the results is called reactiontime (i.e., same as the embedded data variable that I defined) instead of RT; does this mean that I set up the embedded data incorrectly?

    Thank you in advance for your help!

  • rondevrondev Community Member - Trial User Wizard ✭✭✭✭✭

    If you want response time at each page/question, then we can also use timer question at each page.

  • GioDiGioDi LisbonCommunity Member Qubie ✭

    Thanks @rondev, I am aware that it can be done that way, but in my survey I have over 1K questions, so if it can be done with Javascript for the whole survey - or at least for a block within the survey, that would be much preferable.

  • rondevrondev Community Member - Trial User Wizard ✭✭✭✭✭

    @GioDi said:
    Thanks @rondev, I am aware that it can be done that way, but in my survey I have over 1K questions, so if it can be done with Javascript for the whole survey - or at least for a block within the survey, that would be much preferable.

    In this case we need to create embedded data equal to the number of question and then using javascript (written only once) we can capture required information.

  • BardzoGlupiLoginBardzoGlupiLogin Community Member Qubie ✭

    @rondev said:

    @GioDi said:
    Thanks @rondev, I am aware that it can be done that way, but in my survey I have over 1K questions, so if it can be done with Javascript for the whole survey - or at least for a block within the survey, that would be much preferable.

    In this case we need to create embedded data equal to the number of question and then using javascript (written only once) we can capture required information.

    @rondev would you mind posting and example?

    I'm in a similar situation: 10 questionnaire blocks with varying number of items randomized within each block with 1 per page display (advanced randomization).

    I'm using JS to autoadvance questions upon answer click and I'd very much use some modified js code that could store page view times (one question one page) in any way - could be one embedded data filed with comma-sep-values. Whatever will work, as long as I can then match those times with question labels.

  • CColasurdoCColasurdo NJCommunity Member Qubie ✭

    @BardzoGlupiLogin Did you ever get an answer to this question? Also, how did you set it up so you can autoadvance a page using an answer click (instead of hitting the next button?)

Sign In to Comment