mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-06 03:50:04 +02:00
improve beacon
This commit is contained in:
parent
f4a961c393
commit
b0864cb641
1 changed files with 11 additions and 23 deletions
|
@ -451,32 +451,22 @@ function addView(videos_id, currentTime) {
|
||||||
|
|
||||||
var _addViewBeaconAdded = false;
|
var _addViewBeaconAdded = false;
|
||||||
function addViewBeacon() {
|
function addViewBeacon() {
|
||||||
console.log('addViewBeacon', mediaId, playerCurrentTime, seconds_watching_video);
|
console.log('addViewBeacon');
|
||||||
if (_addViewBeaconAdded) {
|
if (_addViewBeaconAdded) {
|
||||||
console.log('addViewBeacon return false');
|
console.log('addViewBeacon return false');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (typeof mediaId !== 'undefined' && typeof playerCurrentTime !== 'undefined' && typeof seconds_watching_video !== 'undefined') {
|
if (typeof mediaId !== 'undefined' && typeof playerCurrentTime !== 'undefined' && typeof seconds_watching_video !== 'undefined') {
|
||||||
console.log('addViewBeacon will be sent', mediaId, playerCurrentTime, seconds_watching_video);
|
console.log('addViewBeacon will be sent', mediaId, playerCurrentTime, seconds_watching_video);
|
||||||
|
|
||||||
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID=' + PHPSESSID;
|
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID=' + PHPSESSID;
|
||||||
let data = new FormData();
|
url = addGetParam(url, 'id', mediaId);
|
||||||
data.append('id', mediaId);
|
url = addGetParam(url, 'currentTime', playerCurrentTime);
|
||||||
data.append('currentTime', playerCurrentTime);
|
url = addGetParam(url, 'seconds_watching_video', seconds_watching_video);
|
||||||
data.append('seconds_watching_video', seconds_watching_video);
|
var beacon = new Image();
|
||||||
|
beacon.src = url;
|
||||||
let result = navigator.sendBeacon(url, data);
|
_addViewBeaconAdded = true;
|
||||||
|
}else{
|
||||||
if (result) {
|
|
||||||
console.log('addViewBeacon Success!');
|
|
||||||
_addViewBeaconAdded = true;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
console.log('addViewBeacon Failure.');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
console.log('addViewBeacon mediaId is undefined');
|
console.log('addViewBeacon mediaId is undefined');
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
|
@ -1271,10 +1261,8 @@ $(document).ready(function () {
|
||||||
$(window).on("unload", function () {
|
$(window).on("unload", function () {
|
||||||
addViewBeacon();
|
addViewBeacon();
|
||||||
});
|
});
|
||||||
window.addEventListener('beforeunload', function (e) {
|
window.addEventListener('beforeunload', function(e) {addViewBeacon();}, false);
|
||||||
addViewBeacon();
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
checkDescriptionArea();
|
checkDescriptionArea();
|
||||||
setInterval(function () {// check for the carousel
|
setInterval(function () {// check for the carousel
|
||||||
checkDescriptionArea();
|
checkDescriptionArea();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue