Fix crash when browser doesn't report page change measurement
This commit is contained in:
parent
6bf1eb105a
commit
22f2d6f292
2 changed files with 10 additions and 3 deletions
|
@ -164,9 +164,13 @@ class Analytics {
|
||||||
}
|
}
|
||||||
|
|
||||||
trackPageChange(generationTimeMs) {
|
trackPageChange(generationTimeMs) {
|
||||||
if (typeof generationTimeMs !== 'number') {
|
if (typeof generationTimeMs === 'number') {
|
||||||
throw new Error('Analytics.trackPageChange: expected generationTimeMs to be a number');
|
this._paq.push(['setGenerationTimeMs', generationTimeMs]);
|
||||||
|
} else {
|
||||||
|
console.warn('Analytics.trackPageChange: expected generationTimeMs to be a number');
|
||||||
|
// But continue anyway because we still want to track the change
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.disabled) return;
|
if (this.disabled) return;
|
||||||
if (this.firstPage) {
|
if (this.firstPage) {
|
||||||
// De-duplicate first page
|
// De-duplicate first page
|
||||||
|
@ -175,7 +179,6 @@ class Analytics {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._paq.push(['setCustomUrl', getRedactedUrl()]);
|
this._paq.push(['setCustomUrl', getRedactedUrl()]);
|
||||||
this._paq.push(['setGenerationTimeMs', generationTimeMs]);
|
|
||||||
this._paq.push(['trackPageView']);
|
this._paq.push(['trackPageView']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -413,6 +413,10 @@ export default React.createClass({
|
||||||
performance.clearMarks('riot_MatrixChat_page_change_start');
|
performance.clearMarks('riot_MatrixChat_page_change_start');
|
||||||
performance.clearMarks('riot_MatrixChat_page_change_stop');
|
performance.clearMarks('riot_MatrixChat_page_change_stop');
|
||||||
const measurement = performance.getEntriesByName('riot_MatrixChat_page_change_delta').pop();
|
const measurement = performance.getEntriesByName('riot_MatrixChat_page_change_delta').pop();
|
||||||
|
|
||||||
|
// In practice, sometimes the entries list is empty, so we get no measurement
|
||||||
|
if (!measurement) return null;
|
||||||
|
|
||||||
return measurement.duration;
|
return measurement.duration;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue