From fd5a8786d0bd7af68d8ad0db37414fb390be4b9b Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sun, 11 Feb 2018 10:27:43 -0500 Subject: [PATCH] Adding Google Analytics --- package.json | 1 + src/analytics.js | 10 ++++++++++ src/pages/404/index.js | 3 +++ src/pages/index/index.js | 3 +++ yarn.lock | 9 ++++++++- 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/analytics.js diff --git a/package.json b/package.json index 301cf5a..bf295da 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "precss": "^3.1.0", "react": "^16.2.0", "react-dom": "^16.2.0", + "react-ga": "^2.4.1", "react-test-renderer": "^16.2.0", "style-loader": "^0.20.1", "svg-react-loader": "^0.4.5", diff --git a/src/analytics.js b/src/analytics.js new file mode 100644 index 0000000..b9595d4 --- /dev/null +++ b/src/analytics.js @@ -0,0 +1,10 @@ +import ReactGA from 'react-ga'; + +const setupGA = () => { + ReactGA.initialize(process.env.GA_PROPERTY, { + debug: (process.env.NODE_ENV !== 'production') + }); + ReactGA.pageview(document.location.pathname); +}; + +export { setupGA }; diff --git a/src/pages/404/index.js b/src/pages/404/index.js index 999e117..5686f4c 100644 --- a/src/pages/404/index.js +++ b/src/pages/404/index.js @@ -1 +1,4 @@ import '../../style.css'; +import { setupGA } from '../../analytics'; + +setupGA(); diff --git a/src/pages/index/index.js b/src/pages/index/index.js index 444cfb0..2655163 100644 --- a/src/pages/index/index.js +++ b/src/pages/index/index.js @@ -5,5 +5,8 @@ import App from '../../components/App'; import '../../style.css'; import '../../service-worker'; +import { setupGA } from '../../analytics'; + +setupGA(); ReactDOM.render(, document.getElementById('root')); diff --git a/yarn.lock b/yarn.lock index ebce3bf..2434ca1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6244,6 +6244,13 @@ react-dom@^16.2.0: object-assign "^4.1.1" prop-types "^15.6.0" +react-ga@^2.4.1: + version "2.4.1" + resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-2.4.1.tgz#dfbd5f028ed39a07067f7a8bf57dc0d240000767" + optionalDependencies: + prop-types "^15.6.0" + react "^15.6.2 || ^16.0" + react-test-renderer@^16.2.0: version "16.2.0" resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.2.0.tgz#bddf259a6b8fcd8555f012afc8eacc238872a211" @@ -6252,7 +6259,7 @@ react-test-renderer@^16.2.0: object-assign "^4.1.1" prop-types "^15.6.0" -react@^16.2.0: +"react@^15.6.2 || ^16.0", react@^16.2.0: version "16.2.0" resolved "https://registry.yarnpkg.com/react/-/react-16.2.0.tgz#a31bd2dab89bff65d42134fa187f24d054c273ba" dependencies: