Javascript for time stamp | XM Community
Skip to main content
Hi,

I'm starting a survey with 3 videos and I need the time the participant pressed 'play'. All I managed to figure out is how to record the timestamp of the onload.



Any Ideas?

Thanks!
Hello @avigail_24 ,



Assuming you have three question which contains one video each on separate page using HTML5 video tag.



Step 1: Create an embedded data(Vid1PlayTime, Vid2PlayTime, Vid3PlayTime) in the survey flow before video questions.



Step 2: Paste the following code in the js(onReady) of your first video question



var s='';

jQuery("video").on('play', function() {

if(s==''){

s= new Date();

Qualtrics.SurveyEngine.setEmbeddedData( 'Vid1PlayTime', s);

}

});



Step 3: The above code will set "Vid1PlayTime" embedded data with timestamp of first video. Similarly paste the above code in other two questions with changing the embedded data variable i.e Vid2PlayTime for Q2 and Vid3PlayTime for Q3
@avigail_24 - I believe you'll need to make one change to @Shashi's code. I think `${date://CurrentDate/c}` is the same as load time because it is resolved on the server before the page is sent to the browser. Use something like `s = new Date();` instead.
> @TomG said:

> @avigail_24 - I believe you'll need to make one change to @Shashi's code. I think `${date://CurrentDate/c}` is the same as load time because it is resolved on the server before the page is sent to the browser. Use something like `s = new Date();` instead.



Thanks @TomG for the correction
Thank you!! That was so helpful (and worked!)

Leave a Reply