Bump flow version #7211

Closed
mayeaux wants to merge 9 commits from bump-flow-version into master
3 changed files with 17 additions and 10 deletions
Showing only changes of commit 9702ee8144 - Show all commits

View file

@ -12,9 +12,9 @@ import { generateInitialUrl } from 'util/url';
import { MATOMO_ID, MATOMO_URL } from 'config'; import { MATOMO_ID, MATOMO_URL } from 'config';
import getConnectionSpeed from 'util/detect-user-bandwidth'; import getConnectionSpeed from 'util/detect-user-bandwidth';
let userDownloadBandwidth; let userDownloadBandwidthInBitsPerSecond;
async function getUserBandwidth() { async function getUserBandwidth() {
userDownloadBandwidth = await getConnectionSpeed(); userDownloadBandwidthInBitsPerSecond = await getConnectionSpeed();
} }
getUserBandwidth(); getUserBandwidth();
@ -120,7 +120,7 @@ function getDeviceType() {
// variables initialized for watchman // variables initialized for watchman
let amountOfBufferEvents = 0; let amountOfBufferEvents = 0;
let amountOfBufferTimeInMS = 0; let amountOfBufferTimeInMS = 0;
let videoType, userId, claimUrl, playerPoweredBy, videoPlayer; let videoType, userId, claimUrl, playerPoweredBy, videoPlayer, bitrateAsBitsPerSecond;
let lastSentTime; let lastSentTime;
// calculate data for backend, send them, and reset buffer data for next interval // calculate data for backend, send them, and reset buffer data for next interval
@ -161,6 +161,8 @@ async function sendAndResetWatchmanData() {
user_id: userId.toString(), user_id: userId.toString(),
position: Math.round(positionInVideo), position: Math.round(positionInVideo),
rel_position: Math.round((positionInVideo / (totalDurationInSeconds * 1000)) * 100), rel_position: Math.round((positionInVideo / (totalDurationInSeconds * 1000)) * 100),
...(userDownloadBandwidthInBitsPerSecond && {bandwidth: userDownloadBandwidthInBitsPerSecond}), // add bandwidth if populated
...(bitrateAsBitsPerSecond && {bitrate: bitrateAsBitsPerSecond}), // add bitrate if video (audio doesn't work)
}; };
// post to watchman // post to watchman
@ -213,8 +215,6 @@ async function sendWatchmanData(body) {
const analytics: Analytics = { const analytics: Analytics = {
// receive buffer events from tracking plugin and save buffer amounts and times for backend call // receive buffer events from tracking plugin and save buffer amounts and times for backend call
videoBufferEvent: async (claim, data) => { videoBufferEvent: async (claim, data) => {
console.log('running here!');
console.log(data);
amountOfBufferEvents = amountOfBufferEvents + 1; amountOfBufferEvents = amountOfBufferEvents + 1;
amountOfBufferTimeInMS = amountOfBufferTimeInMS + data.bufferDuration; amountOfBufferTimeInMS = amountOfBufferTimeInMS + data.bufferDuration;
}, },
@ -251,7 +251,7 @@ const analytics: Analytics = {
startWatchmanIntervalIfNotRunning(); startWatchmanIntervalIfNotRunning();
} }
}, },
videoStartEvent: (claimId, duration, poweredBy, passedUserId, canonicalUrl, passedPlayer) => { videoStartEvent: (claimId, duration, poweredBy, passedUserId, canonicalUrl, passedPlayer, videoBitrate) => {
// populate values for watchman when video starts // populate values for watchman when video starts
userId = passedUserId; userId = passedUserId;
claimUrl = canonicalUrl; claimUrl = canonicalUrl;
@ -259,6 +259,7 @@ const analytics: Analytics = {
videoType = passedPlayer.currentSource().type; videoType = passedPlayer.currentSource().type;
videoPlayer = passedPlayer; videoPlayer = passedPlayer;
bitrateAsBitsPerSecond = videoBitrate;
sendPromMetric('time_to_start', duration); sendPromMetric('time_to_start', duration);
sendMatomoEvent('Media', 'TimeToStart', claimId, duration); sendMatomoEvent('Media', 'TimeToStart', claimId, duration);

View file

@ -168,9 +168,17 @@ function VideoViewer(props: Props) {
} }
analytics.playerStartedEvent(embedded); analytics.playerStartedEvent(embedded);
// convert bytes to bits, and then divide by seconds
const contentInBits = Number(claim.value.source.size) * 8;
const durationInSeconds = claim.value.video && claim.value.video.duration;
let bitrateAsBitsPerSecond;
if (durationInSeconds) {
bitrateAsBitsPerSecond = Math.round(contentInBits / durationInSeconds);
}
fetch(source, { method: 'HEAD', cache: 'no-store' }).then((response) => { fetch(source, { method: 'HEAD', cache: 'no-store' }).then((response) => {
let playerPoweredBy = response.headers.get('x-powered-by') || ''; let playerPoweredBy = response.headers.get('x-powered-by') || '';
analytics.videoStartEvent(claimId, timeToStart, playerPoweredBy, userId, claim.canonical_url, this); analytics.videoStartEvent(claimId, timeToStart, playerPoweredBy, userId, claim.canonical_url, this, bitrateAsBitsPerSecond);
}); });
doAnalyticsView(uri, timeToStart).then(() => { doAnalyticsView(uri, timeToStart).then(() => {

View file

@ -14,9 +14,7 @@ async function measureConnectionSpeed() {
const duration = (endTime - startTime) / 1000; const duration = (endTime - startTime) / 1000;
const bitsLoaded = downloadSize * 8; const bitsLoaded = downloadSize * 8;
const speedBps = (bitsLoaded / duration).toFixed(2); const speedBps = (bitsLoaded / duration).toFixed(2);
const speedKbps = (speedBps / 1024).toFixed(2); return Math.round(Number(speedBps));
const speedMbps = (speedKbps / 1024).toFixed(2);
return speedMbps;
} }
module.exports = measureConnectionSpeed; module.exports = measureConnectionSpeed;