Recording timestamp for item responses on a single page? | XM Community
Skip to main content
Solved

Recording timestamp for item responses on a single page?

  • February 10, 2019
  • 5 replies
  • 370 views

Forum|alt.badge.img+1
Hi all, I am a total Qubie, new to Qualtrics and JS but eager to learn. I am trying to create a survey to measure cognitive load by recording the response time for each question on a 60 question survey. I know the survey platform can do this with the Timing question, but that would require each item to appear on a separate page, which I would like to avoid. My goal is to record a timestamp of the time the page loaded ("PageLoad") and the last click/response ("AnswerTime") for each multiple choice question in a block of 15 questions, and then calculate the total response time ("ResponseTime") by subtracting the time the page loaded from the time each question was answered. I've cobbled together the code below and added each variable to the survey flow as embedded data, but when I export the data I am not getting any information in the cells for the new variables. I've been working in a sample survey by generating responses and adding a few manual responses using a survey link, but no luck so far. Any advice or help the community can offer would be super helpful! Thanks! __ JavaScript for question 5: ``` Qualtrics.SurveyEngine.addOnload(function() { var PageLoad = new Date.now(); Qualtrics.SurveyEngine.setEmbeddedData('PageLoad_QID5', PageLoad); this.questionclick = function(event,element){ if (element.type == 'radio'); var AnswerTime = new Date.now(); Qualtrics.SurveyEngine.setEmbeddedData('AnswerTime_QID5', AnswerTime)}; var ResponseTime = (AnswerTime-PageLoad)/1000; Qualtrics.SurveyEngine.setEmbeddedData('ResponseTime_QID5', ResponseTime); }); ``` __ Image of JavaScript for question 5: ! __ Embedded variables in survey flow: !

Best answer by MeganMarie

Update: I fixed it, and am now getting correct LoadTime, AnswerTime, and ResponseTime for the question in milliseconds. Qualtrics.SurveyEngine.addOnload(function() { var PageLoad = Date.now(); Qualtrics.SurveyEngine.setEmbeddedData('PageLoad_QID5', PageLoad); this.questionclick = function(event,element){ if (element.type == 'radio'); var AnswerTime = Date.now(); Qualtrics.SurveyEngine.setEmbeddedData('AnswerTime_QID5', AnswerTime); var ResponseTime = (AnswerTime - PageLoad); Qualtrics.SurveyEngine.setEmbeddedData('ResponseTime_QID5', ResponseTime); }});

5 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • February 10, 2019
Change `new Date.now()` to `Date.now()`.

Forum|alt.badge.img+1
  • Author
  • February 10, 2019
That worked! I am still not getting data for the Response Time variable, but I am finally getting the ms for LoadTime and AnswerTime, which I can work with. Interestingly, this does not work when I use the survey tools to generate responses, which may explain my earlier failures when I was using just `new Date()`. Thanks!

Forum|alt.badge.img+1
  • Author
  • Answer
  • February 10, 2019
Update: I fixed it, and am now getting correct LoadTime, AnswerTime, and ResponseTime for the question in milliseconds. Qualtrics.SurveyEngine.addOnload(function() { var PageLoad = Date.now(); Qualtrics.SurveyEngine.setEmbeddedData('PageLoad_QID5', PageLoad); this.questionclick = function(event,element){ if (element.type == 'radio'); var AnswerTime = Date.now(); Qualtrics.SurveyEngine.setEmbeddedData('AnswerTime_QID5', AnswerTime); var ResponseTime = (AnswerTime - PageLoad); Qualtrics.SurveyEngine.setEmbeddedData('ResponseTime_QID5', ResponseTime); }});

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • February 11, 2019
> @MeganMarie said: > Interestingly, this does not work when I use the survey tools to generate responses, which may explain my earlier failures when I was using just `new Date()`. Generate responses runs on the server. JavaScript runs on the browser. You will never see data saved with JavaScript in generated responses.

Forum|alt.badge.img+1
  • Author
  • February 11, 2019
> @TomG said: > Generate responses runs on the server. JavaScript runs on the browser. You will never see data saved with JavaScript in generated responses. > Oh, that makes sense. I had read about them being separate but wasn't sure how that applied.