How do I record a keystroke that appears when I export the survey as a CSV file? | XM Community
Skip to main content

I have the following JS:
Qualtrics.SurveyEngine.addOnload(function()


{


var that = this;


Event.observe(document, 'keydown', function keydownCallback(e) { //Set values for keys


  var choiceID = null;


switch (e.keyCode) {


  case 75: // 'k' was pressed


choiceID = 1;


 }


 if (choiceID) {


  Event.stopObserving(document, 'keydown', keydownCallback);


that.setChoiceValue(choiceID, true)


  that.clickNextButton();


 } //Advance when key are pressed


});


});
I am happy that when I type "k," the survey moves forward. However, the survey respondent has the option of clicking on the "Next" button or clicking typing "k." I want to be able to see that the respondent typed "k" (or just clicked "Next") when I export the survey as a CSV file, preferably in a variable.

We can create an embedded data 'hasPressed' and set it's value by default to 0. Then, in the above code just update the embedded data value to 1.

Qualtrics.SurveyEngine.addOnload(function()


{


var that = this;


Event.observe(document, 'keydown', function keydownCallback(e) { //Set values for keys


  var choiceID = null;


switch (e.keyCode) {


  case 75: // 'k' was pressed


choiceID = 1;


 }


 if (choiceID) {


  Event.stopObserving(document, 'keydown', keydownCallback);


that.setChoiceValue(choiceID, true)
Qualtrics.SurveyEngine.setEmbeddedData("hasPressed", "1");

  that.clickNextButton();


 } //Advance when key are pressed


});


});


Leave a Reply