Skip to content

Commit 49a3e66

Browse files
committed
feat(site) Add Google Analytics only for production
1 parent ed2d699 commit 49a3e66

File tree

5 files changed

+42
-34
lines changed

5 files changed

+42
-34
lines changed

DISCUSSION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ this branch:
1212
- [ ] Rethink external population process
1313
- [x] Extract anchors into `_content.json` via `DirectoryTreePlugin` (Fernando)
1414
- [ ] Finish re-incorporating mobile sidebar
15-
- [ ] Re-integrate google-analytics
15+
- [x] Re-integrate google-analytics (Fernando)
1616
- [ ] Re-incorporate `redirects.json`
1717
- [x] Populate page title in `server.jsx` (Fernando)
1818
- [ ] Finish `Navigation` component (greg)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
"react": "^16.2.0",
112112
"react-banner": "^0.5.0",
113113
"react-dom": "^16.2.0",
114+
"react-g-analytics": "0.4.2",
114115
"react-hot-loader": "^4.0.0-beta.12",
115116
"react-router": "^4.2.0",
116117
"react-router-dom": "^4.2.2",

src/index.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import { BrowserRouter, Route } from 'react-router-dom';
3+
import { Route } from 'react-router-dom';
4+
import { BrowserRouter } from 'react-g-analytics';
45
import Site from './components/Site/Site';
56

6-
// TODO: Re-integrate <GoogleAnalytics analyticsId="UA-46921629-2" />
7-
// Consider `react-g-analytics` package
7+
let gaID;
8+
9+
if(process.env.NODE_ENV === 'production') {
10+
gaID = 'UA-46921629-2';
11+
}
812

913
// Client Side Rendering
1014
if ( window.document !== undefined ) {
1115
ReactDOM.render((
12-
<BrowserRouter>
16+
<BrowserRouter id={gaID}>
1317
<Route
1418
path="/"
1519
render={ props => (

webpack.common.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ module.exports = (env = {}) => ({
3636
loader: 'remark-loader',
3737
options: {
3838
plugins: [
39-
// TODO: Add necessary remark plugins
4039
require('./tip'),
4140
require('remark-slug'),
4241
[

webpack.dev.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,35 @@ const HTMLPlugin = require('html-webpack-plugin');
55
const HTMLTemplate = require('html-webpack-template');
66
const common = require('./webpack.common.js');
77

8-
module.exports = env => merge(common(env), {
9-
plugins: [
10-
new webpack.HotModuleReplacementPlugin(),
11-
new HTMLPlugin({
12-
inject: false,
13-
template: HTMLTemplate,
14-
title: 'webpack',
15-
appMountId: 'root',
16-
mobile: true,
17-
favicon: './favicon.ico',
18-
meta: {
19-
description: '...'
20-
}
21-
}),
22-
new webpack.optimize.CommonsChunkPlugin({
23-
name: 'vendor',
24-
chunks: [ 'index' ]
25-
})
26-
],
27-
devServer: {
28-
contentBase: path.resolve(__dirname, './dist'),
29-
port: 3000,
30-
hot: true,
31-
inline: true,
32-
compress: true,
33-
historyApiFallback: true
34-
}
35-
})
8+
module.exports = env =>
9+
merge(common(env), {
10+
plugins: [
11+
new webpack.HotModuleReplacementPlugin(),
12+
new HTMLPlugin({
13+
inject: false,
14+
template: HTMLTemplate,
15+
title: 'webpack',
16+
appMountId: 'root',
17+
mobile: true,
18+
favicon: './favicon.ico',
19+
meta: {
20+
description: '...'
21+
}
22+
}),
23+
new webpack.optimize.CommonsChunkPlugin({
24+
name: 'vendor',
25+
chunks: ['index']
26+
}),
27+
new webpack.DefinePlugin({
28+
'process.env.NODE_ENV': JSON.stringify('development')
29+
})
30+
],
31+
devServer: {
32+
contentBase: path.resolve(__dirname, './dist'),
33+
port: 3000,
34+
hot: true,
35+
inline: true,
36+
compress: true,
37+
historyApiFallback: true
38+
}
39+
});

0 commit comments

Comments
 (0)