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:
!
Page 1 / 1
Change `new Date.now()` to `Date.now()`.
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!
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!
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);
}});
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);
}});
> @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.
> 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.
> @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.
> 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.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.