Java code timestamp each click on a grid | XM Community
Skip to main content

I've got this really neat java code (thanks goes to Holly Dixson) that allows for timestamp each click on a new question. However, the challenge is raised for timestamping each click on a grid where there are multiple sub-questions under one question heading.
I'm posting my current code here and if anyone knows how to twig it so that it records multiple times of clicks on a grid, it'd be really awesome!
Qualtrics.SurveyEngine.addOnload(function()
{
 var timeStampOfOnLoad = new Date();
 Qualtrics.SurveyEngine.setEmbeddedData('timeStampOfOnLoad_QID1', timeStampOfOnLoad);
 //alert('QID1 '+timeStampOfOnLoad);
 this.questionclick = function(event,element){
   var timeStampOfAnswer = new Date();
   Qualtrics.SurveyEngine.setEmbeddedData('timeStampOfAnswer_QID1', timeStampOfAnswer);
   //alert('QID1 '+timeStampOfAnswer);
 }
}
); 

Note: I tried to replace QID1 with QID1_1, QID1_2...and repeat the code to make note of the different clicks on a single grid. It didn't quite work out but maybe I'm just not doing it the right way.

Hi Xixi,
Not sure if this will fit your use case, but you could append all timestamps into the embedded field and then separate them later. This probably won't be ideal if you're running analysis within Qualtrics, but if you're exporting the results and have the freedom to parse them it might work.
var AllTimeStamps = [];

this.questionclick = function(event,element){
   var timeStampOfAnswer = new Date();
AllTimeStamps.push(timeStampOfAnswer,",");
Qualtrics.SurveyEngine.setEmbeddedData('timeStampOfAnswer_QID1', AllTimeStamps);
 }
Not sure how well this will handle users going back and forth on your survey, or leaving and returning, but hopefully it's enough to get started.
Good luck!
EDIT: added a separator to the code block for easier parsing


Thank you so much! bgooldfed
This really helps - at least it will allow me to timestamp multiple clicks in one grid, and that's already a huge piece of info!


Assuming a 'grid' is a likert matrix, what you could do is create a matching text entry matrix as the next question and hide it. When a cell in the first question is clicked you can update the matching cell in the hidden text entry matrix with a timestamp.
Of course, the programming is much more complex than the simple code you've shared above.


https://community.qualtrics.com/XMcommunity/discussion/comment/52313#Comment_52313Hi TomG,
Thank you so much for the answer. I do wonder how you can create a matching text entry matrix and hide it? Sorry I'm a newbie - could you point me in the right direction to go deeper in this direction?


https://community.qualtrics.com/XMcommunity/discussion/comment/52314#Comment_52314That's the easy part. Add a matrix - text entry question with the same number of rows and columns as the first matrix immediately after the first matrix with no page break. Then hide it with JavaScript:
Qualtrics.SurveyEngine.addOnload(function() {
jQuery(this.questionContainer).hide();
});


Leave a Reply