Skip to content

Commit

Permalink
Merge branch 'feature/google-analytics' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gocreating committed Oct 22, 2016
2 parents cd51b77 + 670b27a commit 9af2719
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions configs/project/client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module.exports = {
firebase: require('./firebase/client'),
GA: {
development: {
trackingID: 'UA-86112397-2',
},
production: {
trackingID: 'UA-86112397-1',
},
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"react": "^15.3.2",
"react-bootstrap": "^0.30.5",
"react-dom": "^15.0.2",
"react-ga": "^2.1.2",
"react-helmet": "^3.0.2",
"react-intl": "^2.1.2",
"react-native": "^0.31.0",
Expand Down
8 changes: 7 additions & 1 deletion src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import rootReducer from '../common/reducers';
import getRoutes from '../common/routes';
import setupLocale from './setupLocale';
import setupNProgress from './setupNProgress';
import setupGA from './setupGA';
import { setApiEngine } from '../common/actions/apiEngine';
import ApiEngine from '../common/utils/ApiEngine';

setupNProgress();
setupLocale();
let logPageView = setupGA();
const initialState = window.__INITIAL_STATE__;
let store = createStore(rootReducer, initialState, applyMiddleware(thunk));

Expand All @@ -34,7 +36,11 @@ match({
render(
<Provider store={store}>
<LocaleProvider>
<Router history={browserHistory} {...renderProps}>
<Router
history={browserHistory}
onUpdate={logPageView}
{...renderProps}
>
{routes}
</Router>
</LocaleProvider>
Expand Down
14 changes: 14 additions & 0 deletions src/client/setupGA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import reactGA from 'react-ga';
import configs from '../../configs/project/client';

export default () => {
if (configs.GA) {
reactGA.initialize(configs.GA[process.env.NODE_ENV].trackingID);

return function logPageView() {
reactGA.set({ page: window.location.pathname });
reactGA.pageview(window.location.pathname);
};
}
return undefined;
};

0 comments on commit 9af2719

Please sign in to comment.