I've been trying to use a Javascript to track the plays and pauses of a Youtube video as shown below but have realized that this was for videos from the Qualtrics library. Is there a way to replicate this with an embedded video?
Qualtrics.SurveyEngine.addOnReady(function()
{
pauseTimestamp = null;
playTimestamp = null;
pauses = [];
plays = [];
playCount = 0;
pauseCount = 0;
jQuery("video").on('play', function() {
playCount++;
playTimestamp = Date.now();
if (pauseTimestamp) {
pauses.push(playTimestamp - pauseTimestamp);
}
Qualtrics.SurveyEngine.setEmbeddedData('playCount', playCount);
Qualtrics.SurveyEngine.setEmbeddedData('pauses', pauses.join(";"));
});
jQuery("video").on('pause', function() {
pauseCount++;
pauseTimestamp = Date.now();
plays.push(pauseTimestamp - playTimestamp);
Qualtrics.SurveyEngine.setEmbeddedData('pauseCount', pauseCount);
Qualtrics.SurveyEngine.setEmbeddedData('plays', plays.join(";"));
});
var s='';
jQuery("video").on('play', function() {
if(s==''){
s= Date.now();
Qualtrics.SurveyEngine.setEmbeddedData( 'Vid1Start', s);
}
});
var z='';
jQuery("video").on('pause', function() {
if(z==''){
z= Date.now();
Qualtrics.SurveyEngine.setEmbeddedData( 'Vid1Pause', z);
}
});
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
if (playCount > pauseCount) {
plays.push(Date.now() - playTimestamp);
Qualtrics.SurveyEngine.setEmbeddedData('plays', plays.join(";"));
} else if (pauseCount) {
pauses.push(Date.now() - pauseTimestamp);
Qualtrics.SurveyEngine.setEmbeddedData('pauses', pauses.join(";"));
}
});
Page 1 / 1
We can use youtube API reference for this.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.