holidayextras / barometer

Framework agnostic browser performance metrics
MIT License
5 stars 5 forks source link

Measure page engagement and improve page unload #12

Closed theninj4 closed 7 years ago

theninj4 commented 7 years ago

Partially resolves #11, #6 and #5 by measuring how long users spend on each page.

I've refactored the page unloading functionality into its own file which now triggers the flushing of the buffer along with measuring the final page engagement. Unloading now comes in two forms - a possible unload and a real unload. All possible unloads (moving the mouse off the page, or pressing the CTRL or CMD keys) will simply flush the transport buffer in a typical AJAX manner. When we're leaving the page for sure, we try and use the Beacon API - if it isn't present it we send a synchronous XHR request instead.

Provided all collection mechanisms are very very fast, I see no problems with it. It's likely that most real unloads come after a maybe unload, so the transport buffer will most likely be near-empty. Even on a low-data network on an old-ish version of IE, we're probably only talking about transferring a few hundred bytes.

msaspence commented 7 years ago

A rebase into a single commit would be good. Not worth splitting up at this point, but I feel like this could have been 3 PRs with #6 and #5 getting their own PRs