Created
January 21, 2016 23:10
-
-
Save iansinnott/ed737cfc9e3769ef40c7 to your computer and use it in GitHub Desktop.
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'; | |
import { render } from 'react-dom'; | |
import { Router } from 'react-router'; | |
import createBrowserHistory from 'history/lib/createBrowserHistory'; | |
import routes from './routes.js'; | |
const history = createBrowserHistory(); | |
// Setup google analytics tracking for react router transtions | |
history.listen(location => { | |
window.ga('set', 'page', location.pathname); | |
window.ga('send', 'pageview'); | |
}); | |
render( | |
<Router routes={routes} history={history} />, | |
document.getElementById('root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example using React Router 1.x with Google Analytics
Note that for this to work Google Analytics must already be loaded and present at
window.ga
.