Reaction Time to The First Key Press | XM Community
Skip to main content
Solved

Reaction Time to The First Key Press

  • October 2, 2020
  • 3 replies
  • 125 views

Hi everyone, I am trying to get the RT to the first key press not the first click. I added a JS code in the question in which I want to get the RT. Before that question I added an embedded data with the name of the variable I defined for the RT named as RT. This embedded data and the JS code in which the RT variable is defined is not on the same page as I saw a comment claiming that otherwise the variable is not saved. Yet, the variable RT is still not updated in the data. Do you have any ideas?

The JS code is in a question in the block named "Pişmanlık Anısı"
image.png
And this is the code I use for RT:

Qualtrics.SurveyEngine.addOnload(function () {
 let timeOnLoad = new Date().getTime();
 var that = this;
 Event.observe(document, 'keydown', function keydownCallback(e) {
  var choiceID = e.keyCode;
  if (choiceID) {
   let RT = new Date().getTime() - timeOnLoad;
   console.log(RT);
   Event.stopObserving(document, 'keydown', keydownCallback);
   that.setChoiceValue(choiceID, true);
  }
 });
});

Best answer by TomG

That line of code has to be inside the event - where console.log(RT) is. BTW, if you are seeing the correct value for RT in the console, then you code is working correctly.

3 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • October 2, 2020

A Qualtrics embedded data field and a JS variable are not the same thing. You need to add the line:
Qualtrics.SurveyEngine.setEmbeddedData("RT", RT);


  • Author
  • October 3, 2020

TomG thank you for the reply. I added that line at the end of the JS code but still RT column is empty in the data. When I tried it like
Qualtrics.SurveyEngine.setEmbeddedData("RT", 5); it shows 5 in the data. So maybe there is a problem with the code that I am trying to create RT. But I cannot see what does not work. Do you have any idea how I can check if I can successfully create RT although I do not see it in the data sheet?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • October 3, 2020

That line of code has to be inside the event - where console.log(RT) is. BTW, if you are seeing the correct value for RT in the console, then you code is working correctly.