Skip to content

Instantly share code, notes, and snippets.

@iansinnott
Created January 21, 2016 23:10
Show Gist options
  • Save iansinnott/ed737cfc9e3769ef40c7 to your computer and use it in GitHub Desktop.
Save iansinnott/ed737cfc9e3769ef40c7 to your computer and use it in GitHub Desktop.
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')
);
@iansinnott
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment