Timestamp when an individual submits a page (clicks the next button) | XM Community
Solved

Timestamp when an individual submits a page (clicks the next button)


I am attempting to record the time of when an individual submits a page (clicks the next button).

I know how to do the timing to get how long the participant spent on the page, but I cannot figure out how the get the stamp of the date/time. I think it needs to be done via javascript.
icon

Best answer by TomG 9 May 2018, 21:22

View original

10 replies

Userlevel 7
Badge +27
Use an addOnPageSubmit function. You can get the current date time in JavaScript like this:
```
var datetime = new Date();
```
Hi TomG, (or Qubie)
Are you able to point me to more detail on where to put the javascript and how to return the timestamp in the "raw data" export?
I am also wanting to get a timeDate stamp on each question as the user submits and have that timestamp returned in the csv file of raw data.
any help would be greatly appreciated.
Userlevel 7
Badge +27
> @RogerK said:
> Hi TomG, (or Qubie)
> Are you able to point me to more detail on where to put the javascript and how to return the timestamp in the "raw data" export?
> I am also wanting to get a timeDate stamp on each question as the user submits and have that timestamp returned in the csv file of raw data.
> any help would be greatly appreciated.
There are a number of ways this could be done. I think the easiest is to add a hidden text entry question to each page and populate it with the date on submit. You could create the question once, then copy it as many times as needed and change the question label so you know what question/page it goes with. The question would have this JavaScript:
```
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId).hide();
});
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
jQuery("#"+this.questionId+" input[type=text]").val(new Date());
});
```
Hi Tom,

Thanks for your help! Its working exactly as I wanted now. perfect! I liked your this.questionID variable idea.
Roger
How do I get this to work in a loop and merge block?

Something must be different about the question IDs in loop and merge blocks.
The code hides the question successfully but won't paste the timestamp into the text entry field.
Userlevel 7
Badge +27
> @CanerLC said:
> How do I get this to work in a loop and merge block?
>
> Something must be different about the question IDs in loop and merge blocks.
> The code hides the question successfully but won't paste the timestamp into the text entry field.

Question IDs in a loop & merge start with a number (e.g. 1_QID1), which technically isn't correct (Qualtrics also breaks the id rules with the use of tildes). Anyway, for some reason jQuery doesn't like attributes (e.g. type) in the sub-selector if the the primary selector is an id that starts with a number. So do this instead:
```
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId).hide();
});
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
jQuery("#"+this.questionId+" .InputText").val(new Date());
});
```
@TomG Thank you so much for this!
Userlevel 1
Badge +1
This is great! A quick question. @TomG: What if a participant can go back and look at the same page multiple times? Is there a way to add a second date/time stamp if it detects that one has already be established?
Userlevel 7
Badge +27
> @castleaw said:
> This is great! A quick question. @TomG: What if a participant can go back and look at the same page multiple times? Is there a way to add a second date/time stamp if it detects that one has already be established?

As a separate field each time, not really since you don't know how many times a respondent will go back. You could just look at the input value and if its length is > 0 append a comma and then the new timestamp. You would end up with a comma delimited string of timestamps.
Userlevel 1
Badge +1
Thank you @TomG. What would be the code required to create a comma delimited string of timestamps? Because that would be perfect. Any help you can give would be greatly appreciated!

Leave a Reply