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 amountOfBufferTimeInMS = 0;
|
||||
var videoType, userId, claimUrl, currentVideoPosition, playerPoweredBy, timeAtBuffer;
|
||||
|
||||
var passedPlayer;
|
||||
|
||||
async function sendAndResetWatchmanData(){
|
||||
|
||||
|
@ -115,6 +115,16 @@ async function sendAndResetWatchmanData(){
|
|||
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){
|
||||
timeAtBuffer = Math.round(player.currentTime()) * 1000;
|
||||
}
|
||||
|
@ -182,17 +192,11 @@ const analytics: Analytics = {
|
|||
playerPoweredBy = data.playerPoweredBy;
|
||||
|
||||
timeAtBuffer = data.timeAtBuffer;
|
||||
|
||||
// console.log('RUNNING HERE');
|
||||
//
|
||||
// console.log(claim);
|
||||
// console.log(data);
|
||||
// console.log(player);
|
||||
// console.log('done1234');
|
||||
|
||||
},
|
||||
|
||||
onDispose: () => {
|
||||
stopWatchmanInterval();
|
||||
// TODO: clear data here
|
||||
},
|
||||
videoIsPlaying: () => {
|
||||
startWatchmanIntervalIfNotRunning();
|
||||
|
@ -316,8 +320,14 @@ const analytics: Analytics = {
|
|||
}
|
||||
},
|
||||
|
||||
videoStartEvent: (claimId, duration) => {
|
||||
// TODO: hook into here
|
||||
videoStartEvent: (claimId, duration, poweredBy, canonicalUrl, playerFromView, passedUserId) => {
|
||||
|
||||
userId = passedUserId
|
||||
|
||||
passedPlayer = playerFromView
|
||||
playerPoweredBy = poweredBy;
|
||||
claimUrl = canonicalUrl
|
||||
// TODO: add claim url , userId
|
||||
sendPromMetric('time_to_start', duration);
|
||||
sendMatomoEvent('Media', 'TimeToStart', claimId, duration);
|
||||
},
|
||||
|
|
|
@ -141,6 +141,10 @@ function VideoViewer(props: Props) {
|
|||
}
|
||||
|
||||
function doTrackingFirstPlay(e: Event, data: any) {
|
||||
|
||||
console.log('running here');
|
||||
console.log(userId);
|
||||
|
||||
let timeToStart = data.secondsToLoad;
|
||||
|
||||
if (desktopPlayStartTime !== undefined) {
|
||||
|
@ -148,7 +152,13 @@ function VideoViewer(props: Props) {
|
|||
timeToStart += differenceToAdd;
|
||||
}
|
||||
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(() => {
|
||||
claimRewards();
|
||||
});
|
||||
|
@ -251,7 +261,10 @@ function VideoViewer(props: Props) {
|
|||
});
|
||||
|
||||
player.on('tracking:buffered', doTrackingBuffered);
|
||||
player.on('tracking:firstplay', doTrackingFirstPlay);
|
||||
|
||||
if(userId){
|
||||
player.on('tracking:firstplay', doTrackingFirstPlay);
|
||||
}
|
||||
player.on('ended', onEnded);
|
||||
player.on('play', onPlay);
|
||||
player.on('pause', (event) => onPause(event, player));
|
||||
|
|
Loading…
Reference in a new issue