JavaScript for Reaction Times (trouble producing full string of RTs in Embedded Data) | XM Community
Solved

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!
icon

Best answer by bmills 17 May 2019, 20:41

View original

11 replies

Userlevel 7
Badge +22
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.
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!
Badge
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!
Userlevel 7
Badge +22
If you want response time at each page/question, then we can also use timer question at each page.
Badge
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.
Userlevel 7
Badge +22
> @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 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.

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?)

Hello,
Does anyone know if there is a way to apply this JS to a "Hotspot" question. I need to collect reaction times for each separate "Region" that is clicked. Any information/ help would be helpful.

Is there a way to get the code above to work with a matrix type of question?

Badge

Hi! Im new in this but I am making a survey where I have to track the time they spend on the answers of each question. First of all Im not sure how I supposed to use this JavaScript thing, but also if I put it in every question, where I can find the answers about the timing? Thanks for help

Leave a Reply