From 9fa367b9227deea604c54757661dd8b2c17abd7b Mon Sep 17 00:00:00 2001 From: Pham Hai Duong Date: Thu, 6 Feb 2020 21:41:00 +0800 Subject: [PATCH] feat(marketplace): #44 add google analytics (#191) --- package.json | 1 + packages/marketplace/src/core/index.tsx | 12 ++++++++++-- yarn.lock | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 956461ab9c..27e5f68d8b 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "react-datasheet": "^1.4.0", "react-datepicker": "^2.9.6", "react-dom": "^16.12.0", + "react-ga": "^2.7.0", "react-google-map": "^3.1.1", "react-google-maps-loader": "^4.2.5", "react-icons": "^3.7.0", diff --git a/packages/marketplace/src/core/index.tsx b/packages/marketplace/src/core/index.tsx index 3e05c94dfe..258b0693ed 100644 --- a/packages/marketplace/src/core/index.tsx +++ b/packages/marketplace/src/core/index.tsx @@ -8,9 +8,17 @@ import store from './store' import Toast from '../components/ui/toast' import ToastMessage from '../components/ui/toast-message' import { PortalProvider } from '@reapit/elements' +import ReactGA from 'react-ga' -if (process.env.NODE_ENV === 'production') { - Sentry.init({ dsn: process.env.SENTRY_PROJECT_URL_MARKETPLACE }) +const { NODE_ENV, MARKETPLACE_GOOGLE_ANALYTICS_KEY, SENTRY_PROJECT_URL } = process.env + +if (NODE_ENV !== 'development' && SENTRY_PROJECT_URL) { + Sentry.init({ dsn: (SENTRY_PROJECT_URL as any).MARKETPLACE }) +} + +if (NODE_ENV !== 'development' && MARKETPLACE_GOOGLE_ANALYTICS_KEY) { + ReactGA.initialize(MARKETPLACE_GOOGLE_ANALYTICS_KEY) + ReactGA.pageview(window.location.pathname + window.location.search) } const rootElement = document.querySelector('#root') as Element diff --git a/yarn.lock b/yarn.lock index 88356da1c0..025579205d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18408,6 +18408,11 @@ react-focus-lock@^2.1.0: use-callback-ref "^1.2.1" use-sidecar "^1.0.1" +react-ga@^2.7.0: + version "2.7.0" + resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-2.7.0.tgz#24328f157f31e8cffbf4de74a3396536679d8d7c" + integrity sha512-AjC7UOZMvygrWTc2hKxTDvlMXEtbmA0IgJjmkhgmQQ3RkXrWR11xEagLGFGaNyaPnmg24oaIiaNPnEoftUhfXA== + react-google-map@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/react-google-map/-/react-google-map-3.1.1.tgz#e47e42287ef6bc7510422fbfd5014ab2b4a0d1b4"