我怎样才能知道用户在我的网站上观看了多少秒的视频?
How can I find out how many seconds a user watches a video on my website?
我正在使用 vjs 视频播放器。我想我应该检查用户是否点击了播放或暂停按钮。然后我可以数出过去了多少秒。为此,我需要这个跨度值。
İf 值等于暂停我要开始 count.So 这就是为什么我需要 JavaScript 到达那里的代码。
我必须到达带下划线的文字:
<script>
$(document).ready(function () {
var sayac=0;//input ile sayaca sayı ata,kaçtan başlanacağı
var kac_saniyede_bir=10;//veritabanıcalisacak
var degisken1;//zamanlama
var ip_adres;
function sure_arttir() {
var dizi=verileri_getir();
if(dizi.includes("vjs-ended")){
clearInterval(degisken1);
}
sayac++;
console.log(sayac);
if(sayac%kac_saniyede_bir==0 || dizi.includes("vjs-ended")){
//ajax kodu
console.log(ip_adres);
console.log("veritabanına eklendi");
}
}
function video_baslat_durdur(durum){
getUserIP(function(ip){ip_adres=ip;});
if (durum) {
if(!degisken1){
degisken1= setInterval(sure_arttir, 1000);
}
}else{
clearInterval(degisken1);
degisken1=null;
}
}
$(".vjs-icon-placeholder").mouseup(function() {
var dizi=verileri_getir();
video_baslat_durdur(dizi.includes("vjs-paused"));
});
$("#my-video").keyup(function() {
var dizi=verileri_getir();
video_baslat_durdur(dizi.includes("vjs-paused"));
});
$("#my-video_html5_api").mouseup(function() {
var dizi=verileri_getir();
video_baslat_durdur(!dizi.includes("vjs-paused"));
});
$(".vjs-poster").mouseup(function() {
var dizi=verileri_getir();
video_baslat_durdur(dizi.includes("vjs-paused"));
});
});
function verileri_getir(){
var sinif=($("#my-video").attr("class"));
var dizi=sinif.split(" ");
return dizi;
}
function getUserIP(onNewIP) { // onNewIp - your listener function for new IPs
//compatibility for firefox and chrome
var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var pc = new myPeerConnection({
iceServers: []
}),
noop = function() {},
localIPs = {},
ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g,
key;
function iterateIP(ip) {
if (!localIPs[ip]) onNewIP(ip);
localIPs[ip] = true;
}
//create a bogus data channel
pc.createDataChannel("");
// create offer and set local description
pc.createOffer().then(function(sdp) {
sdp.sdp.split('\n').forEach(function(line) {
if (line.indexOf('candidate') < 0) return;
line.match(ipRegex).forEach(iterateIP);
});
pc.setLocalDescription(sdp, noop, noop);
}).catch(function(reason) {
// An error occurred, so handle the failure to connect
});
//listen for candidate events
pc.onicecandidate = function(ice) {
if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;
ice.candidate.candidate.match(ipRegex).forEach(iterateIP);
};
}
</script>
<script src="https://vjs.zencdn.net/7.1.0/video.js"></script>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link href="https://vjs.zencdn.net/7.1.0/video-js.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/ie8/ie8-version/videojs-ie8.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<video id="my-video" class="video-js" controls preload="auto" width="640" height="264"
poster="MY_VIDEO_POSTER.jpg" data-setup="{}">
<source id="video" src="MY_VIDEO.mp4" type='video/mp4'>
<source src="MY_VIDEO.webm" type='video/webm'>
<p class="vjs-no-js">
To view this video please enable JavaScript, and consider upgrading to a web browser that
<a href="https://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
</p>
</video>
</body>
我正在使用 vjs 视频播放器。我想我应该检查用户是否点击了播放或暂停按钮。然后我可以数出过去了多少秒。为此,我需要这个跨度值。
İf 值等于暂停我要开始 count.So 这就是为什么我需要 JavaScript 到达那里的代码。
我必须到达带下划线的文字:
<script>
$(document).ready(function () {
var sayac=0;//input ile sayaca sayı ata,kaçtan başlanacağı
var kac_saniyede_bir=10;//veritabanıcalisacak
var degisken1;//zamanlama
var ip_adres;
function sure_arttir() {
var dizi=verileri_getir();
if(dizi.includes("vjs-ended")){
clearInterval(degisken1);
}
sayac++;
console.log(sayac);
if(sayac%kac_saniyede_bir==0 || dizi.includes("vjs-ended")){
//ajax kodu
console.log(ip_adres);
console.log("veritabanına eklendi");
}
}
function video_baslat_durdur(durum){
getUserIP(function(ip){ip_adres=ip;});
if (durum) {
if(!degisken1){
degisken1= setInterval(sure_arttir, 1000);
}
}else{
clearInterval(degisken1);
degisken1=null;
}
}
$(".vjs-icon-placeholder").mouseup(function() {
var dizi=verileri_getir();
video_baslat_durdur(dizi.includes("vjs-paused"));
});
$("#my-video").keyup(function() {
var dizi=verileri_getir();
video_baslat_durdur(dizi.includes("vjs-paused"));
});
$("#my-video_html5_api").mouseup(function() {
var dizi=verileri_getir();
video_baslat_durdur(!dizi.includes("vjs-paused"));
});
$(".vjs-poster").mouseup(function() {
var dizi=verileri_getir();
video_baslat_durdur(dizi.includes("vjs-paused"));
});
});
function verileri_getir(){
var sinif=($("#my-video").attr("class"));
var dizi=sinif.split(" ");
return dizi;
}
function getUserIP(onNewIP) { // onNewIp - your listener function for new IPs
//compatibility for firefox and chrome
var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var pc = new myPeerConnection({
iceServers: []
}),
noop = function() {},
localIPs = {},
ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g,
key;
function iterateIP(ip) {
if (!localIPs[ip]) onNewIP(ip);
localIPs[ip] = true;
}
//create a bogus data channel
pc.createDataChannel("");
// create offer and set local description
pc.createOffer().then(function(sdp) {
sdp.sdp.split('\n').forEach(function(line) {
if (line.indexOf('candidate') < 0) return;
line.match(ipRegex).forEach(iterateIP);
});
pc.setLocalDescription(sdp, noop, noop);
}).catch(function(reason) {
// An error occurred, so handle the failure to connect
});
//listen for candidate events
pc.onicecandidate = function(ice) {
if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;
ice.candidate.candidate.match(ipRegex).forEach(iterateIP);
};
}
</script>
<script src="https://vjs.zencdn.net/7.1.0/video.js"></script>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link href="https://vjs.zencdn.net/7.1.0/video-js.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/ie8/ie8-version/videojs-ie8.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<video id="my-video" class="video-js" controls preload="auto" width="640" height="264"
poster="MY_VIDEO_POSTER.jpg" data-setup="{}">
<source id="video" src="MY_VIDEO.mp4" type='video/mp4'>
<source src="MY_VIDEO.webm" type='video/webm'>
<p class="vjs-no-js">
To view this video please enable JavaScript, and consider upgrading to a web browser that
<a href="https://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
</p>
</video>
</body>