I'm trying to implement custom Javascript with embedded data to capture keystrokes for text-input question, but the variable is always blank when I check the dataset after testing.
The same code is implemented in two text-input questions. Participants are randomized to see only one of them, and I want to capture keystroke data regardless of which one they see.
I was originally trying to collect multiple datapoints (total key presses, back spaces, paste events, etc.), but couldn't get the values to save in the output data (the column is always just blank) so I simplified the code to just capture total key presses and still can't get it to work (the column is still blank every time I test it. I've verified that the embedded data is defined at the very top of the survey, I've added a debugging alert to make sure the javascript is running (which it is), and I've confirmed that the field names match exactly ("TotalKeypresses"), but still no luck (the column is blank in the dataset).
Here's the simplified Javascript I'm using right now to just try to get total keystrokes:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function() {
alert("JS running"); // This will show a popup when the page loads
var keyCount = 0; // Initializes the counter
document.onkeydown = function(event) {
keyCount++; // Increments the counter for ANY key press
Qualtrics.SurveyEngine.setEmbeddedData("TotalKeypresses", keyCount); // Saves count to embedded data
}
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Any help would be much appreciated! Thank you!
