JS code to add time stamps for question unload/onload | XM Community
Skip to main content

Hi there,
I know next to nothing about JS. I added two embedded variables to a survey (timeStampPRE and timeStampPOST). Now I am trying to get these variables to populate with the time when a participant starts and ends a key block within the survey.
I tried adding javascipt to the question before the key block...
Qualtrics.SurveyEngine.addOnUnload(function()
{
var timeStampPRE = new Date();
});

and the next question after the key block....
Qualtrics.SurveyEngine.addOnload(function()
{
 var timeStampPOST = new Date();
});
But the fields show up as blank. How can I get these timestamps to show up in the embedded data fields?
Thank you!
Liz

First, you have to define the embedded data fields in the survey flow (e.g. timeStampPost). Then in your JS:
var timeStampPOST = Date();
Qualtrics.SurveyEngine.setEmbeddedData("timeStampPost",timeStampPost);


Leave a Reply