Skip to content

Commit

Permalink
feat: add google analytics
Browse files Browse the repository at this point in the history
closes #73
  • Loading branch information
juancarlosfarah committed May 6, 2019
1 parent f9cd556 commit ead4dbc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/store/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10765,6 +10765,11 @@ react-event-listener@^0.6.2:
prop-types "^15.6.0"
warning "^4.0.1"

[email protected]:
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"
Expand Down

0 comments on commit ead4dbc

Please sign in to comment.