From fc2dd6b9f8be404d822d0c9e938e3436fd7f5842 Mon Sep 17 00:00:00 2001 From: GC-Park Date: Mon, 25 Sep 2023 16:26:10 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20Google=20Analytics=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package-lock.json | 17 +++++++++++++++++ frontend/package.json | 1 + frontend/src/router.tsx | 14 ++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2ae903e9..af131d6a 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "@types/react-router-dom": "^5.3.3", + "history": "^5.3.0", "msw-storybook-addon": "^1.8.0", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -14197,6 +14198,14 @@ "resolved": "https://registry.npmjs.org/headers-polyfill/-/headers-polyfill-3.1.2.tgz", "integrity": "sha512-tWCK4biJ6hcLqTviLXVR9DTRfYGQMXEIUj3gwJ2rZ5wO/at3XtkI4g8mCvFdUF9l1KMBNCfmNAdnahm1cgavQA==" }, + "node_modules/history": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/history/-/history-5.3.0.tgz", + "integrity": "sha512-ZqaKwjjrAYUYfLG+htGaIIZ4nioX2L70ZUMIFysS3xvBsSG4x/n1V6TXV3N8ZYNuFGlDirFg32T7B6WOUPDYcQ==", + "dependencies": { + "@babel/runtime": "^7.7.6" + } + }, "node_modules/hoist-non-react-statics": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", @@ -34533,6 +34542,14 @@ "resolved": "https://registry.npmjs.org/headers-polyfill/-/headers-polyfill-3.1.2.tgz", "integrity": "sha512-tWCK4biJ6hcLqTviLXVR9DTRfYGQMXEIUj3gwJ2rZ5wO/at3XtkI4g8mCvFdUF9l1KMBNCfmNAdnahm1cgavQA==" }, + "history": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/history/-/history-5.3.0.tgz", + "integrity": "sha512-ZqaKwjjrAYUYfLG+htGaIIZ4nioX2L70ZUMIFysS3xvBsSG4x/n1V6TXV3N8ZYNuFGlDirFg32T7B6WOUPDYcQ==", + "requires": { + "@babel/runtime": "^7.7.6" + } + }, "hoist-non-react-statics": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", diff --git a/frontend/package.json b/frontend/package.json index 0c2b0d3e..274f834a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -17,6 +17,7 @@ "license": "ISC", "dependencies": { "@types/react-router-dom": "^5.3.3", + "history": "^5.3.0", "msw-storybook-addon": "^1.8.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/frontend/src/router.tsx b/frontend/src/router.tsx index 7f5833bd..d6659f41 100644 --- a/frontend/src/router.tsx +++ b/frontend/src/router.tsx @@ -5,6 +5,8 @@ import RootPage from './pages/RootPage'; import { ReactNode } from 'react'; import AuthLayout from './components/Layout/AuthLayout'; import NotFound from './pages/NotFound'; +import ReactGA from 'react-ga'; +import { createBrowserHistory as createHistory } from 'history'; const SelectedTopic = lazy(() => import('./pages/SelectedTopic')); const NewPin = lazy(() => import('./pages/NewPin')); @@ -18,6 +20,15 @@ const Profile = lazy(() => import('./pages/Profile')); const AskLogin = lazy(() => import('./pages/AskLogin')); const Bookmark = lazy(() => import('./pages/Bookmark')); +const gaTrackingId = process.env.REACT_APP_GA_TRACKING_ID || ''; + +ReactGA.initialize(gaTrackingId, { debug: true }); +const history = createHistory(); +history.listen((location: any) => { + ReactGA.set({ page: location.pathname }); + ReactGA.pageview(location.pathname); +}); + interface routeElement { path: string; element: ReactNode; @@ -181,3 +192,6 @@ const router = createBrowserRouter( ); export default router; +function createBrowserHistory() { + throw new Error('Function not implemented.'); +} From bbf0642d14c1889853db1611cc301059015d6192 Mon Sep 17 00:00:00 2001 From: GC-Park Date: Mon, 25 Sep 2023 16:33:25 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/router.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/src/router.tsx b/frontend/src/router.tsx index d6659f41..80ab6647 100644 --- a/frontend/src/router.tsx +++ b/frontend/src/router.tsx @@ -192,6 +192,3 @@ const router = createBrowserRouter( ); export default router; -function createBrowserHistory() { - throw new Error('Function not implemented.'); -}