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.

Revisions

  1. mwq27 revised this gist Feb 27, 2018. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions trackingMiddleware.ts
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    const trackPage = function(page: string, state: any) {
    ReactGA.set({
    page,
    ...options,
    });
    ReactGA.pageview(page);
    };

    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);
    };
  2. mwq27 created this gist Feb 27, 2018.
    15 changes: 15 additions & 0 deletions trackingMiddleware.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    const trackPage = function(page: string, state: any) {
    ReactGA.set({
    page,
    ...options,
    });
    ReactGA.pageview(page);
    };

    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);
    };