add logging of player point of presence

This commit is contained in:
Jeremy Kauffman 2020-09-09 09:57:32 -04:00 committed by Sean Yesmunt
parent 2c22aee126
commit fb142f7699
3 changed files with 35 additions and 24 deletions

View file

@ -38,7 +38,14 @@ type Analytics = {
videoStartEvent: (string, number) => void, videoStartEvent: (string, number) => void,
videoBufferEvent: ( videoBufferEvent: (
StreamClaim, StreamClaim,
{ timeAtBuffer: number, bufferDuration: number, bitRate: number, duration: number, userIdHash: string } {
timeAtBuffer: number,
bufferDuration: number,
bitRate: number,
duration: number,
userIdHash: string,
playerPoweredBy: string,
}
) => void, ) => void,
emailProvidedEvent: () => void, emailProvidedEvent: () => void,
emailVerifiedEvent: () => void, emailVerifiedEvent: () => void,
@ -185,32 +192,32 @@ const analytics: Analytics = {
sendPromMetric('time_to_start', duration); sendPromMetric('time_to_start', duration);
sendMatomoEvent('Media', 'TimeToStart', claimId, duration); sendMatomoEvent('Media', 'TimeToStart', claimId, duration);
}, },
videoBufferEvent: (claim, data) => {
// @if TARGET='web'
sendPromMetric('buffer');
// @endif
videoBufferEvent: (claim, data) => {
sendMatomoEvent('Media', 'BufferTimestamp', claim.claim_id, data.timeAtBuffer); sendMatomoEvent('Media', 'BufferTimestamp', claim.claim_id, data.timeAtBuffer);
fetch(LBRY_WEB_BUFFER_API, { if (LBRY_WEB_BUFFER_API) {
method: 'post', fetch(LBRY_WEB_BUFFER_API, {
headers: { method: 'post',
Accept: 'application/json', headers: {
'Content-Type': 'application/json', Accept: 'application/json',
}, 'Content-Type': 'application/json',
body: JSON.stringify({
device: 'web',
type: 'buffering',
client: data.userIdHash,
data: {
url: claim.canonical_url,
position: data.timeAtBuffer,
duration: data.bufferDuration,
stream_duration: data.duration,
stream_bitrate: data.bitRate,
}, },
}), body: JSON.stringify({
}); device: 'web',
type: 'buffering',
client: data.userIdHash,
data: {
url: claim.canonical_url,
position: data.timeAtBuffer,
duration: data.bufferDuration,
player: data.playerPoweredBy,
stream_duration: data.duration,
stream_bitrate: data.bitRate,
},
}),
});
}
}, },
tagFollowEvent: (tag, following) => { tagFollowEvent: (tag, following) => {
sendMatomoEvent('Tag', following ? 'Tag-Follow' : 'Tag-Unfollow', tag); sendMatomoEvent('Tag', following ? 'Tag-Follow' : 'Tag-Unfollow', tag);

View file

@ -87,7 +87,10 @@ function VideoViewer(props: Props) {
}, [uri, previousUri]); }, [uri, previousUri]);
function doTrackingBuffered(e: Event, data: any) { function doTrackingBuffered(e: Event, data: any) {
doAnalyticsBuffer(uri, data); fetch(source, { method: 'HEAD' }).then(response => {
data.playerPoweredBy = response.headers.get('x-powered-by');
doAnalyticsBuffer(uri, data);
});
} }
function doTrackingFirstPlay(e: Event, data: any) { function doTrackingFirstPlay(e: Event, data: any) {

View file

@ -491,6 +491,7 @@ export function doAnalyticsBuffer(uri, bufferData) {
bitRate, bitRate,
userIdHash, userIdHash,
duration: fileDurationInSeconds, duration: fileDurationInSeconds,
playerPoweredBy: bufferData.playerPoweredBy,
}); });
}; };
} }