seems to be working well but needs a cleanup
This commit is contained in:
parent
5b2c808f78
commit
4895218279
2 changed files with 36 additions and 13 deletions
|
@ -104,7 +104,7 @@ var durationInSeconds = 10;
|
||||||
var amountOfBufferEvents = 0;
|
var amountOfBufferEvents = 0;
|
||||||
var amountOfBufferTimeInMS = 0;
|
var amountOfBufferTimeInMS = 0;
|
||||||
var videoType, userId, claimUrl, currentVideoPosition, playerPoweredBy, timeAtBuffer;
|
var videoType, userId, claimUrl, currentVideoPosition, playerPoweredBy, timeAtBuffer;
|
||||||
|
var passedPlayer;
|
||||||
|
|
||||||
async function sendAndResetWatchmanData(){
|
async function sendAndResetWatchmanData(){
|
||||||
|
|
||||||
|
@ -115,6 +115,16 @@ async function sendAndResetWatchmanData(){
|
||||||
protocol = 'stb';
|
protocol = 'stb';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var playerToUse = player || passedPlayer;
|
||||||
|
|
||||||
|
if(!playerToUse){
|
||||||
|
return console.log('no player to use')
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!userId){
|
||||||
|
return console.log('no user id')
|
||||||
|
}
|
||||||
|
|
||||||
if(!timeAtBuffer){
|
if(!timeAtBuffer){
|
||||||
timeAtBuffer = Math.round(player.currentTime()) * 1000;
|
timeAtBuffer = Math.round(player.currentTime()) * 1000;
|
||||||
}
|
}
|
||||||
|
@ -182,17 +192,11 @@ const analytics: Analytics = {
|
||||||
playerPoweredBy = data.playerPoweredBy;
|
playerPoweredBy = data.playerPoweredBy;
|
||||||
|
|
||||||
timeAtBuffer = data.timeAtBuffer;
|
timeAtBuffer = data.timeAtBuffer;
|
||||||
|
|
||||||
// console.log('RUNNING HERE');
|
|
||||||
//
|
|
||||||
// console.log(claim);
|
|
||||||
// console.log(data);
|
|
||||||
// console.log(player);
|
|
||||||
// console.log('done1234');
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onDispose: () => {
|
onDispose: () => {
|
||||||
stopWatchmanInterval();
|
stopWatchmanInterval();
|
||||||
|
// TODO: clear data here
|
||||||
},
|
},
|
||||||
videoIsPlaying: () => {
|
videoIsPlaying: () => {
|
||||||
startWatchmanIntervalIfNotRunning();
|
startWatchmanIntervalIfNotRunning();
|
||||||
|
@ -316,8 +320,14 @@ const analytics: Analytics = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
videoStartEvent: (claimId, duration) => {
|
videoStartEvent: (claimId, duration, poweredBy, canonicalUrl, playerFromView, passedUserId) => {
|
||||||
// TODO: hook into here
|
|
||||||
|
userId = passedUserId
|
||||||
|
|
||||||
|
passedPlayer = playerFromView
|
||||||
|
playerPoweredBy = poweredBy;
|
||||||
|
claimUrl = canonicalUrl
|
||||||
|
// TODO: add claim url , userId
|
||||||
sendPromMetric('time_to_start', duration);
|
sendPromMetric('time_to_start', duration);
|
||||||
sendMatomoEvent('Media', 'TimeToStart', claimId, duration);
|
sendMatomoEvent('Media', 'TimeToStart', claimId, duration);
|
||||||
},
|
},
|
||||||
|
|
|
@ -141,6 +141,10 @@ function VideoViewer(props: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function doTrackingFirstPlay(e: Event, data: any) {
|
function doTrackingFirstPlay(e: Event, data: any) {
|
||||||
|
|
||||||
|
console.log('running here');
|
||||||
|
console.log(userId);
|
||||||
|
|
||||||
let timeToStart = data.secondsToLoad;
|
let timeToStart = data.secondsToLoad;
|
||||||
|
|
||||||
if (desktopPlayStartTime !== undefined) {
|
if (desktopPlayStartTime !== undefined) {
|
||||||
|
@ -148,7 +152,13 @@ function VideoViewer(props: Props) {
|
||||||
timeToStart += differenceToAdd;
|
timeToStart += differenceToAdd;
|
||||||
}
|
}
|
||||||
analytics.playerStartedEvent(embedded);
|
analytics.playerStartedEvent(embedded);
|
||||||
analytics.videoStartEvent(claimId, timeToStart);
|
// TODO: add userId, claim URL,
|
||||||
|
|
||||||
|
fetch(source, { method: 'HEAD' }).then((response) => {
|
||||||
|
var playerPoweredBy = response.headers.get('x-powered-by');
|
||||||
|
analytics.videoStartEvent(claimId, timeToStart, playerPoweredBy, claim && claim.canonical_url, player, userId);
|
||||||
|
});
|
||||||
|
|
||||||
doAnalyticsView(uri, timeToStart).then(() => {
|
doAnalyticsView(uri, timeToStart).then(() => {
|
||||||
claimRewards();
|
claimRewards();
|
||||||
});
|
});
|
||||||
|
@ -251,7 +261,10 @@ function VideoViewer(props: Props) {
|
||||||
});
|
});
|
||||||
|
|
||||||
player.on('tracking:buffered', doTrackingBuffered);
|
player.on('tracking:buffered', doTrackingBuffered);
|
||||||
player.on('tracking:firstplay', doTrackingFirstPlay);
|
|
||||||
|
if(userId){
|
||||||
|
player.on('tracking:firstplay', doTrackingFirstPlay);
|
||||||
|
}
|
||||||
player.on('ended', onEnded);
|
player.on('ended', onEnded);
|
||||||
player.on('play', onPlay);
|
player.on('play', onPlay);
|
||||||
player.on('pause', (event) => onPause(event, player));
|
player.on('pause', (event) => onPause(event, player));
|
||||||
|
|
Loading…
Add table
Reference in a new issue