From da6f04e647d3a7571e2c53efb0fdb9029cf51a6e Mon Sep 17 00:00:00 2001 From: Fernando Montoya Date: Wed, 11 Apr 2018 20:20:09 +0200 Subject: [PATCH 1/2] feat(site) Add Google Analytics only for production --- DISCUSSION.md | 2 +- package.json | 1 + src/index.jsx | 12 ++++++---- webpack.common.js | 10 +++++++- webpack.dev.js | 60 +++++++++++++++++++++++++---------------------- 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/DISCUSSION.md b/DISCUSSION.md index 4a06819d20cb..5483d8de2e5f 100644 --- a/DISCUSSION.md +++ b/DISCUSSION.md @@ -12,7 +12,7 @@ this branch: - [ ] Rethink external population process - [ ] Extract anchors into `_content.json` via `DirectoryTreePlugin` - [ ] Finish re-incorporating mobile sidebar -- [ ] Re-integrate google-analytics +- [x] Re-integrate google-analytics (Fernando) - [ ] Re-incorporate `redirects.json` - [ ] Populate page title in `server.jsx` (fernando) - [ ] Finish `Navigation` component (greg) diff --git a/package.json b/package.json index 1647646766a3..3068e28fe1eb 100644 --- a/package.json +++ b/package.json @@ -111,6 +111,7 @@ "react": "^16.2.0", "react-banner": "^0.5.0", "react-dom": "^16.2.0", + "react-g-analytics": "0.4.2", "react-hot-loader": "^4.0.0-beta.12", "react-router": "^4.2.0", "react-router-dom": "^4.2.2", diff --git a/src/index.jsx b/src/index.jsx index fc205186f3a7..82265b499a0b 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -1,15 +1,19 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { BrowserRouter, Route } from 'react-router-dom'; +import { Route } from 'react-router-dom'; +import { BrowserRouter } from 'react-g-analytics'; import Site from './components/Site/Site'; -// TODO: Re-integrate -// Consider `react-g-analytics` package +let gaID; + +if(process.env.NODE_ENV === 'production') { + gaID = 'UA-46921629-2'; +} // Client Side Rendering if ( window.document !== undefined ) { ReactDOM.render(( - + ( diff --git a/webpack.common.js b/webpack.common.js index 1b2cab52b8c9..b8225109a062 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -35,7 +35,15 @@ module.exports = (env = {}) => ({ options: { plugins: [ // TODO: Add necessary remark plugins - require('remark-autolink-headings'), + require('./tip'), + require('remark-slug'), + [ + require('remark-autolink-headings'), + { + behaviour: 'append' + } + ], + require('remark-html'), require('remark-mermaid') ] } diff --git a/webpack.dev.js b/webpack.dev.js index 8614dea647ee..17bfe740a9a0 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -5,31 +5,35 @@ const HTMLPlugin = require('html-webpack-plugin'); const HTMLTemplate = require('html-webpack-template'); const common = require('./webpack.common.js'); -module.exports = env => merge(common(env), { - plugins: [ - new webpack.HotModuleReplacementPlugin(), - new HTMLPlugin({ - inject: false, - template: HTMLTemplate, - title: 'webpack', - appMountId: 'root', - mobile: true, - favicon: './favicon.ico', - meta: { - description: '...' - } - }), - new webpack.optimize.CommonsChunkPlugin({ - name: 'vendor', - chunks: [ 'index' ] - }) - ], - devServer: { - contentBase: path.resolve(__dirname, './dist'), - port: 3000, - hot: true, - inline: true, - compress: true, - historyApiFallback: true - } -}) +module.exports = env => + merge(common(env), { + plugins: [ + new webpack.HotModuleReplacementPlugin(), + new HTMLPlugin({ + inject: false, + template: HTMLTemplate, + title: 'webpack', + appMountId: 'root', + mobile: true, + favicon: './favicon.ico', + meta: { + description: '...' + } + }), + new webpack.optimize.CommonsChunkPlugin({ + name: 'vendor', + chunks: ['index'] + }), + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify('development') + }) + ], + devServer: { + contentBase: path.resolve(__dirname, './dist'), + port: 3000, + hot: true, + inline: true, + compress: true, + historyApiFallback: true + } + }); From 58c38e07fbb01ea6d27717b445700e995e7f6ba7 Mon Sep 17 00:00:00 2001 From: Fernando Montoya Date: Sat, 14 Apr 2018 21:33:10 +0200 Subject: [PATCH 2/2] fix(site) Add Google Analytics only in production --- src/index.jsx | 14 ++++------- webpack.common.js | 10 +------- webpack.dev.js | 63 +++++++++++++++++++++++------------------------ 3 files changed, 37 insertions(+), 50 deletions(-) diff --git a/src/index.jsx b/src/index.jsx index 82265b499a0b..69e70c636df1 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -1,19 +1,15 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { Route } from 'react-router-dom'; -import { BrowserRouter } from 'react-g-analytics'; +import { BrowserRouter, Route } from 'react-router-dom'; +import AnalyticsRouter from 'react-g-analytics'; import Site from './components/Site/Site'; -let gaID; - -if(process.env.NODE_ENV === 'production') { - gaID = 'UA-46921629-2'; -} +const Router = process.env.NODE_ENV === 'production' ? AnalyticsRouter : BrowserRouter; // Client Side Rendering if ( window.document !== undefined ) { ReactDOM.render(( - + ( @@ -21,6 +17,6 @@ if ( window.document !== undefined ) { { ...props } import={ path => import(`./content/${path}`) } /> )} /> - + ), document.getElementById('root')); } diff --git a/webpack.common.js b/webpack.common.js index b8225109a062..1b2cab52b8c9 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -35,15 +35,7 @@ module.exports = (env = {}) => ({ options: { plugins: [ // TODO: Add necessary remark plugins - require('./tip'), - require('remark-slug'), - [ - require('remark-autolink-headings'), - { - behaviour: 'append' - } - ], - require('remark-html'), + require('remark-autolink-headings'), require('remark-mermaid') ] } diff --git a/webpack.dev.js b/webpack.dev.js index 17bfe740a9a0..91f2d1ac1dea 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -5,35 +5,34 @@ const HTMLPlugin = require('html-webpack-plugin'); const HTMLTemplate = require('html-webpack-template'); const common = require('./webpack.common.js'); -module.exports = env => - merge(common(env), { - plugins: [ - new webpack.HotModuleReplacementPlugin(), - new HTMLPlugin({ - inject: false, - template: HTMLTemplate, - title: 'webpack', - appMountId: 'root', - mobile: true, - favicon: './favicon.ico', - meta: { - description: '...' - } - }), - new webpack.optimize.CommonsChunkPlugin({ - name: 'vendor', - chunks: ['index'] - }), - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify('development') - }) - ], - devServer: { - contentBase: path.resolve(__dirname, './dist'), - port: 3000, - hot: true, - inline: true, - compress: true, - historyApiFallback: true - } - }); +module.exports = env => merge(common(env), { + plugins: [ + new webpack.HotModuleReplacementPlugin(), + new HTMLPlugin({ + inject: false, + template: HTMLTemplate, + title: 'webpack', + appMountId: 'root', + mobile: true, + favicon: './favicon.ico', + meta: { + description: '...' + } + }), + new webpack.optimize.CommonsChunkPlugin({ + name: 'vendor', + chunks: ['index'] + }), + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify('development') + }) + ], + devServer: { + contentBase: path.resolve(__dirname, './dist'), + port: 3000, + hot: true, + inline: true, + compress: true, + historyApiFallback: true + } +})