Add environment variable to disable Google Analytics. #70 (#87)

pull/91/head
Lucian I. Last 7 years ago committed by Alex Kern
parent 41b2fcab0d
commit 4e46ec7a0b

@ -1,6 +1,8 @@
FROM node:latest FROM node:latest
MAINTAINER Alex Kern <alex@kern.io> MAINTAINER Alex Kern <alex@kern.io>
ENV GA_ACCESS_TOKEN
COPY . ./ COPY . ./
RUN npm install && npm run build RUN npm install && npm run build

@ -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'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 ## Development
$ git clone https://github.com/kern/filepizza.git $ git clone https://github.com/kern/filepizza.git

@ -6,8 +6,10 @@ import SupportStore from "../stores/SupportStore";
import { RouteHandler } from "react-router"; import { RouteHandler } from "react-router";
import ga from "react-google-analytics"; import ga from "react-google-analytics";
ga("create", "UA-62785624-1", "auto"); if (process.env.GA_ACCESS_TOKEN) {
ga("create", process.env.GA_ACCESS_TOKEN, "auto");
ga("send", "pageview"); ga("send", "pageview");
}
export default class App extends React.Component { export default class App extends React.Component {
constructor() { constructor() {
@ -89,7 +91,7 @@ export default class App extends React.Component {
</p> </p>
</footer> </footer>
<script>FilePizza()</script> <script>FilePizza()</script>
<ga.Initializer /> { process.env.GA_ACCESS_TOKEN ? <ga.Initializer /> : <div></div> }
</body> </body>
</html> </html>
); );

@ -53,6 +53,8 @@
"nib": "^1.1.0", "nib": "^1.1.0",
"node-uuid": "^1.4.3", "node-uuid": "^1.4.3",
"nodemon": "^1.4.1", "nodemon": "^1.4.1",
"noop-loader": "^1.0.0",
"null-loader": "^0.1.1",
"react": "^0.13.0", "react": "^0.13.0",
"react-frozenhead": "^0.3.0", "react-frozenhead": "^0.3.0",
"react-google-analytics": "^0.2.0", "react-google-analytics": "^0.2.0",

@ -1,4 +1,5 @@
const nib = require("nib"); const nib = require("nib");
const webpack = require('webpack')
module.exports = { module.exports = {
entry: "./lib/client", 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: { node: {
fs: "empty" fs: "empty"
}, },
stylus: { stylus: {
use: [nib()] use: [nib()]
} },
rules: [{
test: /react-google-analytics/,
use: process.env.GA_ACCESS_TOKEN ? 'null-loader' : 'noop-loader'
}]
}; };

Loading…
Cancel
Save