feat(Ads): Add averageLoadTime and errors to ad stats (#6828)

This commit is contained in:
Álvaro Velad Galván
2024-06-18 19:13:24 +02:00
committed by GitHub
parent e613972b94
commit 037d4cbb7e
5 changed files with 38 additions and 1 deletions
+7 -1
View File
@@ -12,9 +12,11 @@
/**
* @typedef {{
* loadTimes: !Array.<number>,
* averageLoadTime: number,
* started: number,
* playedCompletely: number,
* skipped: number
* skipped: number,
* errors: number
* }}
*
* @description
@@ -22,12 +24,16 @@
*
* @property {number} loadTimes
* The set of amounts of time it took to get the final manifest.
* @property {number} averageLoadTime
* The average time it took to get the final manifest.
* @property {number} started
* The number of ads started.
* @property {number} playedCompletely
* The number of ads played completely.
* @property {number} skipped
* The number of ads skipped.
* @property {number} errors
* The number of ads with errors.
* @exportDoc
*/
shaka.extern.AdsStats;
+3
View File
@@ -852,6 +852,9 @@ shaka.ads.AdManager = class extends shaka.util.FakeEventTarget {
case shaka.ads.AdManager.AD_SKIPPED:
this.stats_.incrementSkipped();
break;
case shaka.ads.AdManager.AD_ERROR:
this.stats_.incrementErrors();
break;
}
}
this.dispatchEvent(event);
+24
View File
@@ -24,6 +24,8 @@ shaka.ads.AdsStats = class {
this.playedCompletely_ = 0;
/** @private {number} */
this.skipped_ = 0;
/** @private {number} */
this.errors_ = 0;
}
/**
@@ -56,6 +58,26 @@ shaka.ads.AdsStats = class {
this.skipped_++;
}
/**
* Increase the number of ads with error by one.
*/
incrementErrors() {
this.errors_++;
}
/**
* @return {number}
* @private
*/
getAverageLoadTime_() {
if (!this.loadTimes_.length) {
return 0;
}
const sum = this.loadTimes_.reduce(
(accumulator, currentValue) => accumulator + currentValue, 0);
return sum / this.loadTimes_.length;
}
/**
* Create a stats blob that we can pass up to the app. This blob will not
* reference any internal data.
@@ -65,9 +87,11 @@ shaka.ads.AdsStats = class {
getBlob() {
return {
loadTimes: this.loadTimes_,
averageLoadTime: this.getAverageLoadTime_(),
started: this.started_,
playedCompletely: this.playedCompletely_,
skipped: this.skipped_,
errors: this.errors_,
};
}
};
+2
View File
@@ -98,9 +98,11 @@ shaka.ui.AdStatisticsButton = class extends shaka.ui.Element {
/** @private {!Object.<string, function(string):string>} */
this.parseFrom_ = {
'loadTimes': parseLoadTimes,
'averageLoadTime': showNumber,
'started': showNumber,
'playedCompletely': showNumber,
'skipped': showNumber,
'errors': showNumber,
};
/** @private {shaka.util.Timer} */
+2
View File
@@ -219,9 +219,11 @@ shaka.ui.Overlay = class {
],
adStatisticsList: [
'loadTimes',
'averageLoadTime',
'started',
'playedCompletely',
'skipped',
'errors',
],
contextMenuElements: [
'loop',