-
-
Notifications
You must be signed in to change notification settings - Fork 831
Track duration of page changes #1814
Changes from 1 commit
69d9080
c8312dd
187e8ab
f29b58a
8d994f2
00167fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ class Analytics { | |
this._paq = null; | ||
this.disabled = true; | ||
this.firstPage = true; | ||
this.generationTimeMs = null; | ||
} | ||
|
||
/** | ||
|
@@ -147,6 +148,23 @@ class Analytics { | |
return true; | ||
} | ||
|
||
startPageChangeTimer() { | ||
performance.clearMarks('riot_page_change_start'); | ||
performance.mark('riot_page_change_start'); | ||
} | ||
|
||
stopPageChangeTimer() { | ||
performance.mark('riot_page_change_stop'); | ||
performance.measure( | ||
'riot_page_change_delta', | ||
'riot_page_change_start', | ||
'riot_page_change_stop', | ||
); | ||
|
||
const measurement = performance.getEntriesByName('riot_page_change_delta').pop(); | ||
this.generationTimeMs = measurement.duration; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way you're calling this (ie. with willupdate / didupdate) this looks fine, but if these can ever overlap then this will go very wonky, so might be worth calling this out. Also, any reason, not to clear the marks as soon as we have our number? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As in, with docs on the functions?
Nope, I guess not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, or in conjunction with comment below, change the API so start returns some unique handle that you then pass into |
||
} | ||
|
||
trackPageChange() { | ||
if (this.disabled) return; | ||
if (this.firstPage) { | ||
|
@@ -156,6 +174,9 @@ class Analytics { | |
return; | ||
} | ||
this._paq.push(['setCustomUrl', getRedactedUrl()]); | ||
if (typeof this.generationTimeMs === 'number') { | ||
this._paq.push(['setGenerationTimeMs', this.generationTimeMs]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Saving this as a member variable seems like quite an error prone API: is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True that we'd leak incorrect generation times when we don't use both in conjunction. We could set it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above, but nulling it out is probably acceptable. |
||
} | ||
this._paq.push(['trackPageView']); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll have to use these APIs conditionally: they aren't available in all browsers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://caniuse.com/#feat=user-timing says otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes - MDN lied to me! Fair enough then.