Skip to content

Commit 9af2719

Browse files
committed
Merge branch 'feature/google-analytics' into dev
2 parents cd51b77 + 670b27a commit 9af2719

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

configs/project/client.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
module.exports = {
22
firebase: require('./firebase/client'),
3+
GA: {
4+
development: {
5+
trackingID: 'UA-86112397-2',
6+
},
7+
production: {
8+
trackingID: 'UA-86112397-1',
9+
},
10+
},
311
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"react": "^15.3.2",
113113
"react-bootstrap": "^0.30.5",
114114
"react-dom": "^15.0.2",
115+
"react-ga": "^2.1.2",
115116
"react-helmet": "^3.0.2",
116117
"react-intl": "^2.1.2",
117118
"react-native": "^0.31.0",

src/client/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import rootReducer from '../common/reducers';
99
import getRoutes from '../common/routes';
1010
import setupLocale from './setupLocale';
1111
import setupNProgress from './setupNProgress';
12+
import setupGA from './setupGA';
1213
import { setApiEngine } from '../common/actions/apiEngine';
1314
import ApiEngine from '../common/utils/ApiEngine';
1415

1516
setupNProgress();
1617
setupLocale();
18+
let logPageView = setupGA();
1719
const initialState = window.__INITIAL_STATE__;
1820
let store = createStore(rootReducer, initialState, applyMiddleware(thunk));
1921

@@ -34,7 +36,11 @@ match({
3436
render(
3537
<Provider store={store}>
3638
<LocaleProvider>
37-
<Router history={browserHistory} {...renderProps}>
39+
<Router
40+
history={browserHistory}
41+
onUpdate={logPageView}
42+
{...renderProps}
43+
>
3844
{routes}
3945
</Router>
4046
</LocaleProvider>

src/client/setupGA.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import reactGA from 'react-ga';
2+
import configs from '../../configs/project/client';
3+
4+
export default () => {
5+
if (configs.GA) {
6+
reactGA.initialize(configs.GA[process.env.NODE_ENV].trackingID);
7+
8+
return function logPageView() {
9+
reactGA.set({ page: window.location.pathname });
10+
reactGA.pageview(window.location.pathname);
11+
};
12+
}
13+
return undefined;
14+
};

0 commit comments

Comments
 (0)