On one of my website I am using a vimeo video link to show a video. Now I am having a requirement to track the video progress. like the duration a learner spent on that particular page or the percentage of video viewed by the user. Is it possible to track this in JavaScript
Using player.js you can use the below code
<script src="https://player.vimeo.com/api/player.js">
const player = new Vimeo.Player("video_id");
player.on('timeupdate', function(data){
console.log( data.seconds );
});
Hope it will help you.
I have used it with a WordPress site to track the progress using the code below:
player.on('timeupdate', function(data){
var running_time = data.seconds;
$.ajax({
url : '<?php echo admin_url("admin-ajax.php" ) ?>',
data : {
action: "storeinDB",
user_id : "<?php echo $user->ID; ?>",
post_id : "<?php echo get_the_ID(); ?>",
running_time : running_time },
dataType : "post",
type: "post",
success: function(response){
//console.log(response);
}
});
});
thanks
Related resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With