Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1874 from matrix-org/luke/fix-analytics-crash
Browse files Browse the repository at this point in the history
Fix crash when browser doesn't report page change measurement
  • Loading branch information
lukebarnard1 authored May 3, 2018
2 parents fecbac0 + 3ba51ba commit b08abd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,22 @@ class Analytics {
}

trackPageChange(generationTimeMs) {
if (typeof generationTimeMs !== 'number') {
throw new Error('Analytics.trackPageChange: expected generationTimeMs to be a number');
}
if (this.disabled) return;
if (this.firstPage) {
// De-duplicate first page
// router seems to hit the fn twice
this.firstPage = false;
return;
}

if (typeof generationTimeMs === '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
}

this._paq.push(['setCustomUrl', getRedactedUrl()]);
this._paq.push(['setGenerationTimeMs', generationTimeMs]);
this._paq.push(['trackPageView']);
}

Expand Down
4 changes: 4 additions & 0 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ export default React.createClass({
performance.clearMarks('riot_MatrixChat_page_change_start');
performance.clearMarks('riot_MatrixChat_page_change_stop');
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;
},

Expand Down

0 comments on commit b08abd3

Please sign in to comment.