Wrap react components with a HOC measuring page performance metrics. This packages assumes you're tracking via segment and is simply providing a react-y HOC implementation of the website-performance npm module.
If you've loaded segment globally, and are guranteed to have window.analytics defined before your code runs .. integrating is as easy as:
PureComponent...windowanalyticsMyPage eventName: 'Performance.Track'
In other cases, you may have asynchronously loaded a tracking library. Integrating would then look something like this:
const analytics =PureComponent...analyticsMyPage
website-performance-hoc can take any analytics provider as long as it has a
.track() method, so it should work with Google analytics and Segment. If you're using an analytics provider that doesn't have a
.track() method, please open an issue.
componentDidMount in the
HOC which can be invoked before the
DOM has loaded. In that case, we set
window.onload to retry tracking once the window has loaded. We're also deferring the track call to when the browser has free cycles using request-callback.
Questions? Feedback? Please let me know
WWWWWW||WWWWWW W W W||W W W || ( OO )__________ / | \ /o o| MIT \ \___/||_||__||_|| * || || || || _||_|| _||_|| (__|__|(__|__|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.