Skip to content

Instantly share code, notes, and snippets.

@mwq27
Last active February 27, 2018 14:47
Show Gist options
  • Select an option

  • Save mwq27/a17c77ae2a889ed0f64ae8ceed05a303 to your computer and use it in GitHub Desktop.

Select an option

Save mwq27/a17c77ae2a889ed0f64ae8ceed05a303 to your computer and use it in GitHub Desktop.
const trackingMiddleware = (store: Store<any>) => (next: Dispatch<any>) => (action: Action) => {
if (action.type === '@@router/LOCATION_CHANGE') {
const nextPage = `${action.payload.pathname}${action.payload.search}`;
trackPage(nextPage, store.getState());
}
return next(action);
};
function trackPage(page: string, state: any) {
ReactGA.set({
page,
...options,
});
ReactGA.pageview(page);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment