Embed Data from Custom Javascript - Reaction time "Keypress"

verenialverenial NZCommunity Member - Trial User Qubie ✭
edited October 2019 in Custom Code

Embed Data from Custom Javascript - Reaction time "Keypress"

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

Sign In to Comment