Skip to content

Instantly share code, notes, and snippets.

@UberMouse
Last active July 3, 2017 05:08
Show Gist options
  • Save UberMouse/0e71da7d684ad6619e369eb8e3898f5e to your computer and use it in GitHub Desktop.
Save UberMouse/0e71da7d684ad6619e369eb8e3898f5e to your computer and use it in GitHub Desktop.
Log a React components render time to Raygun with a custom timing
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