Skip to content

Instantly share code, notes, and snippets.

@UberMouse
Created July 3, 2017 04:30
Show Gist options
  • Save UberMouse/bc96f43c9aa0953a465867812a412fdc to your computer and use it in GitHub Desktop.
Save UberMouse/bc96f43c9aa0953a465867812a412fdc to your computer and use it in GitHub Desktop.
Tracking React Router navigation events with Raygun4JS
import { withRouter } from 'react-router'
class App extends Component {
constructor(props) {
super(props);
this.props.history.listen((location, action) => {
window.rg4js('trackEvent', { type: 'pageView', path: location.pathname });
});
}
render() {
return (
<Route exact path="/" Component={...} />
<Route exact path="/Home" Component={...} />
);
}
}
export default withRouter(App);
import AppContainer from './AppContainer';
import { BrowserRouter, Route } from 'react-router-dom';
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById('root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment