1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 19:42:38 +02:00

improve beacon

This commit is contained in:
Daniel 2021-08-02 16:40:15 -03:00
parent f4a961c393
commit b0864cb641

View file

@ -451,32 +451,22 @@ function addView(videos_id, currentTime) {
var _addViewBeaconAdded = false;
function addViewBeacon() {
console.log('addViewBeacon', mediaId, playerCurrentTime, seconds_watching_video);
console.log('addViewBeacon');
if (_addViewBeaconAdded) {
console.log('addViewBeacon return false');
return false;
}
if (typeof mediaId !== 'undefined' && typeof playerCurrentTime !== 'undefined' && typeof seconds_watching_video !== 'undefined') {
console.log('addViewBeacon will be sent', mediaId, playerCurrentTime, seconds_watching_video);
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID=' + PHPSESSID;
let data = new FormData();
data.append('id', mediaId);
data.append('currentTime', playerCurrentTime);
data.append('seconds_watching_video', seconds_watching_video);
let result = navigator.sendBeacon(url, data);
if (result) {
console.log('addViewBeacon Success!');
_addViewBeaconAdded = true;
return true;
} else {
console.log('addViewBeacon Failure.');
return false;
}
} else {
url = addGetParam(url, 'id', mediaId);
url = addGetParam(url, 'currentTime', playerCurrentTime);
url = addGetParam(url, 'seconds_watching_video', seconds_watching_video);
var beacon = new Image();
beacon.src = url;
_addViewBeaconAdded = true;
}else{
console.log('addViewBeacon mediaId is undefined');
}
return '';
@ -1271,10 +1261,8 @@ $(document).ready(function () {
$(window).on("unload", function () {
addViewBeacon();
});
window.addEventListener('beforeunload', function (e) {
addViewBeacon();
}, false);
window.addEventListener('beforeunload', function(e) {addViewBeacon();}, false);
checkDescriptionArea();
setInterval(function () {// check for the carousel
checkDescriptionArea();