Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easiest way to log current location on route change? #240

Closed
Robinnnnn opened this issue Feb 23, 2016 · 2 comments
Closed

Easiest way to log current location on route change? #240

Robinnnnn opened this issue Feb 23, 2016 · 2 comments

Comments

@Robinnnnn
Copy link

Is it possible to log the current window location every time there's a route change?

I know this is possible in react-router using an onUpdate handler. ReduxRouter doesn't come with such a handler. Could I set up some middleware somehow in my store?

@mjrussell
Copy link
Contributor

You could use a history listener instead. Theres an example here for React Router - https://github.com/tcoopman/ga-react-router. Updated for redux-rotuer (untested):

import { createHistory } from 'history';
const history = createHistory()

// Listen for changes to the current location. The
// listener is called once immediately.
const unlisten = history.listen(location => {
  ga('send', location);
});

// Configure reducer to store state at state.router
// You can store it elsewhere by specifying a custom `routerStateSelector`
// in the store enhancer below
const reducer = combineReducers({
  router: routerStateReducer,
  //app: rootReducer, //you can combine all your other reducers under a single namespace like so
});

// Compose reduxReactRouter with other store enhancers
const store = compose(
  applyMiddleware(m1, m2, m3),
  reduxReactRouter({
    routes,
    history
  }),
  devTools()
)(createStore)(reducer);

React.render(<ReduxRoute/>, el)

@silouanwright
Copy link

thanks for posting that example, got it working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants