Last active
July 3, 2017 05:08
-
-
Save UberMouse/0e71da7d684ad6619e369eb8e3898f5e to your computer and use it in GitHub Desktop.
Log a React components render time to Raygun with a custom timing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
// This has not been tested with a browser that doesn't support the window.performance api | |
export default function LogRenderingTime(Component) { | |
let boot = 0; | |
class LogRenderTime extends React.Component { | |
constructor(props) { | |
super(props); | |
boot = window.performance ? performance.now() : 0; | |
} | |
componentDidMount() { | |
const renderTime = window.performance ? performance.now() - boot : 0; | |
rg4js('trackEvent', { | |
type: 'customTimings', | |
timings: { | |
custom1: renderTime | |
} | |
}); | |
} | |
render() { | |
return <Component {...this.props} />; | |
} | |
} | |
return LogRenderTime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment