How to measure time a respondent takes to type an input | XM Community
Skip to main content
Question

How to measure time a respondent takes to type an input

  • March 5, 2021
  • 3 replies
  • 100 views

I have two input textboxes per question, and I'm trying to measure the time it takes them to fill out both textboxes.
I guess I could start a timer for a keydown/keypressed eventListener or even use Qualtric API's questionclick function (if I understood it right), but I'm not sure when to end the timer esp. because there may be some time lapse between the respondent finishing typing and clicking on the next button. Does anyone know how to deal with this?

3 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • March 5, 2021

assign a listener to oninput of the text boxes. Store the time of each input as an array. Keep the first and last.


  • Author
  • March 5, 2021

@ahmedA
hmm how do I refer to the text boxes though? for example, I know the next button is referred to as NextButton, but I'm not sure what to call the text box inputs.
could you show me an example of using oninput on textboxes?


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • March 5, 2021

Here's the code:
Qualtrics.SurveyEngine.addOnReady(function () {
    let quest = this;
    let time_arrays = {};
    let all_inputs = quest.questionContainer.querySelectorAll(".InputText");
    all_inputs.forEach((text_box) => {
        time_arrays[text_box.id] = [];
        text_box.oninput = function () {
            time_arrays[text_box.id].push(Date.now());
        };
    });
    document.querySelector("#NextButton").onclick = function () {
        Object.keys(time_arrays).forEach((id) => {
            let id_time = time_arrays[id].pop() - time_arrays[id].shift();
            Qualtrics.SurveyEngine.setEmbeddedData(id.replaceAll("~", "_") + "_time", id_time);
        });
    };
});

It should work for any question with a text entry box. You'll have to setup embedded variables looking like the image below.
image.png