diff --git a/package.json b/package.json index 2df9c0d4..b38e6216 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "scripts": { "dev": "yarn react-scripts start", "build": "env-cmd ./.env react-scripts build", - "start": "concurrently \"cross-env BROWSER=none yarn react-scripts start\" \"wait-on http://localhost:3000 && env-cmd ./.env electron .\"", + "start": "concurrently \"env-cmd ./.env.local react-scripts start\" \"wait-on http://localhost:3000 && env-cmd ./.env.local electron .\"", "pack": "electron-builder --dir", "postinstall": "electron-builder install-app-deps", "predist": "yarn build", @@ -71,6 +71,7 @@ "react-detect-offline": "2.3.0", "react-dev-utils": "9.0.0", "react-dom": "16.8.6", + "react-ga": "2.5.7", "react-loading": "2.0.3", "react-redux": "7.0.3", "react-redux-toastr": "7.4.9", diff --git a/src/index.js b/src/index.js index 8aa5637a..6bb52aa8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ import React from 'react'; +import ReactGa from 'react-ga'; import ReactDOM from 'react-dom'; import './index.css'; import { Provider } from 'react-redux'; @@ -7,11 +8,14 @@ import 'react-redux-toastr/lib/css/react-redux-toastr.min.css'; import App from './App'; import configureStore from './store/configure'; -// set up sentry -const { SENTRY_DSN } = process.env; +const { REACT_APP_SENTRY_DSN, REACT_APP_GOOGLE_ANALYTICS_ID } = process.env; + +// set up google analytics +ReactGa.initialize(REACT_APP_GOOGLE_ANALYTICS_ID); +// set up sentry Sentry.init({ - dsn: SENTRY_DSN, + dsn: REACT_APP_SENTRY_DSN, beforeSend(event) { // check if it is an exception, and if so, show the report dialog if (event.exception) { diff --git a/src/store/configure.js b/src/store/configure.js index 0b8d71ef..912546e3 100644 --- a/src/store/configure.js +++ b/src/store/configure.js @@ -4,6 +4,7 @@ import { createBrowserHistory } from 'history'; import { connectRouter, routerMiddleware } from 'connected-react-router'; import ReduxThunk from 'redux-thunk'; import ReduxPromise from 'redux-promise'; +import ReactGa from 'react-ga'; import reducers from '../reducers'; /** @@ -14,6 +15,10 @@ import reducers from '../reducers'; const configure = state => { // apply history to the middleware const history = createBrowserHistory(); + history.listen(location => { + ReactGa.set({ page: location.pathname }); + ReactGa.pageview(location.pathname); + }); const RouterMiddleware = routerMiddleware(history); // create the store diff --git a/yarn.lock b/yarn.lock index 03fee7b5..a3030a2d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10765,6 +10765,11 @@ react-event-listener@^0.6.2: prop-types "^15.6.0" warning "^4.0.1" +react-ga@2.5.7: + version "2.5.7" + resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-2.5.7.tgz#1c80a289004bf84f84c26d46f3a6a6513081bf2e" + integrity sha512-UmATFaZpEQDO96KFjB5FRLcT6hFcwaxOmAJZnjrSiFN/msTqylq9G+z5Z8TYzN/dbamDTiWf92m6MnXXJkAivQ== + react-is@^16.6.0, react-is@^16.6.3, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6: version "16.8.6" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"