Embed Data from Custom Javascript - Reaction time "Keypress" | XM Community
Skip to main content
Dear community,



I'd love some help on a current problem I am working on. I want to record the time until the user presses the first key on the survey to fill out a text box. I have written some custom Javascript to do so:



```

Qualtrics.SurveyEngine.addOnload(function()

{

let timeOnLoad = new Date().getTime();

var eventHandler = function(event)

{

console.log("pressed")

let timeTaken = new Date().getTime() - timeOnLoad;

console.log(timeTaken)

Qualtrics.SurveyEngine.setEmbeddedData( 'time_press_key ', timeTaken );

document.removeEventListener('keypress', eventHandler);

}

document.addEventListener('keypress', eventHandler);

});

```



I have also set up a Embedded Variable in my survey flow, but the data does not come through. I would really appreciate some help on this issue of where I might be going wrong.



!





Thanks so much in advance for your help!



Verena
Be the first to reply!

Leave a Reply