From cbb7f4c800fae511b13f7481dbfb055156dc8add Mon Sep 17 00:00:00 2001 From: "Lucian I. Last" Date: Fri, 16 Nov 2018 15:06:00 +0100 Subject: [PATCH] Add environment variable to disable Google Analytics. #70 --- Dockerfile | 4 +++- README.md | 2 ++ lib/components/App.js | 8 +++++--- package.json | 2 ++ webpack.config.js | 16 +++++++++++++++- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index a63a7b1..96890f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM node:latest MAINTAINER Alex Kern - + +ENV GA_ACCESS_TOKEN + COPY . ./ RUN npm install && npm run build diff --git a/README.md b/README.md index 00992c3..39d1944 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ You can also use [zeit/now](https://zeit.co/now): If you'd like to use [Twilio's STUN/TURN service](https://www.twilio.com/stun-turn) for better connectivity behind NATs, you can specify your SID and token using the `TWILIO_SID` and `TWILIO_TOKEN` environment variables, respectively. +If you want to use [Google Analytics](https://marketingplatform.google.com/about/analytics/), you can specify your UA code using the `GA_ACCESS_TOKEN="UA-00000000-1"` environment variable. + ## Development $ git clone https://github.com/kern/filepizza.git diff --git a/lib/components/App.js b/lib/components/App.js index daabd7a..ca40ec0 100644 --- a/lib/components/App.js +++ b/lib/components/App.js @@ -6,8 +6,10 @@ import SupportStore from "../stores/SupportStore"; import { RouteHandler } from "react-router"; import ga from "react-google-analytics"; -ga("create", "UA-62785624-1", "auto"); -ga("send", "pageview"); +if (process.env.GA_ACCESS_TOKEN) { + ga("create", process.env.GA_ACCESS_TOKEN, "auto"); + ga("send", "pageview"); +} export default class App extends React.Component { constructor() { @@ -89,7 +91,7 @@ export default class App extends React.Component {

- + { process.env.GA_ACCESS_TOKEN ? :
} ); diff --git a/package.json b/package.json index 405b616..e87a482 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,8 @@ "nib": "^1.1.0", "node-uuid": "^1.4.3", "nodemon": "^1.4.1", + "noop-loader": "^1.0.0", + "null-loader": "^0.1.1", "react": "^0.13.0", "react-frozenhead": "^0.3.0", "react-google-analytics": "^0.2.0", diff --git a/webpack.config.js b/webpack.config.js index 172ee70..a193b79 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,4 +1,5 @@ const nib = require("nib"); +const webpack = require('webpack') module.exports = { entry: "./lib/client", @@ -26,11 +27,24 @@ module.exports = { ] }, + plugins: [ + new webpack.DefinePlugin({ + 'process.env': { + 'GA_ACCESS_TOKEN': JSON.stringify(process.env.GA_ACCESS_TOKEN), + } + }) + ], + node: { fs: "empty" }, stylus: { use: [nib()] - } + }, + + rules: [{ + test: /react-google-analytics/, + use: process.env.GA_ACCESS_TOKEN ? 'null-loader' : 'noop-loader' + }] };