From 915bca1b1b702f843f2dee73ea79b5359ab616af Mon Sep 17 00:00:00 2001 From: Hongxin Date: Tue, 20 Jun 2023 09:59:41 -0400 Subject: [PATCH] Upgrade to google analytics 4 (#990) Co-authored-by: Calvin Lu <59149377+calvinlu3@users.noreply.github.com> --- package.json | 1 + src/main/webapp/app/App.tsx | 10 ++++++++-- src/main/webapp/index.html | 15 +-------------- yarn.lock | 5 +++++ 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 664b1ab57..702c7d239 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "react-day-picker": "^7.4.8", "react-document-title": "^2.0.3", "react-dom": "16.13.1", + "react-ga4": "^2.1.0", "react-highlight-words": "^0.16.0", "react-hot-loader": "4.12.20", "react-html-parser": "^2.0.2", diff --git a/src/main/webapp/app/App.tsx b/src/main/webapp/app/App.tsx index b6ca055f4..86fcc53e9 100644 --- a/src/main/webapp/app/App.tsx +++ b/src/main/webapp/app/App.tsx @@ -1,4 +1,6 @@ import * as React from 'react'; +import ReactGA from 'react-ga4'; + import Main from './Main'; import AppStore, { IAppConfig } from 'app/store/AppStore'; import AuthenticationStore from 'app/store/AuthenticationStore'; @@ -13,9 +15,8 @@ import { PAGE_TITLE, PAGE_ROUTE } from 'app/config/constants'; import { action } from 'mobx'; import autobind from 'autobind-decorator'; import { getPageTitle } from 'app/shared/utils/Utils'; -import Reaptcha from 'reaptcha'; import { setRecaptchaToken } from './indexUtils'; -import { COILinkout } from './pages/teamPage/COILinkout'; +import { AppConfig } from 'app/appConfig'; export type Stores = { appStore: AppStore; @@ -94,6 +95,11 @@ class App extends React.Component { this.checkHash(history); + // Install Google Analytics 4 if GA project id is configured on server side + if (AppConfig.serverConfig?.googleAnalyticsProjectId) { + ReactGA.initialize(AppConfig.serverConfig.googleAnalyticsProjectId); + } + return ( <> diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index 0c00f904f..0b746d25e 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -120,7 +120,7 @@

You must enable javascript to view this page.

/*]]>*/ - --> - - - diff --git a/yarn.lock b/yarn.lock index 4c24b1825..b23c0f44d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14901,6 +14901,11 @@ react-file-download@^0.3.2: resolved "https://registry.yarnpkg.com/react-file-download/-/react-file-download-0.3.5.tgz#7a4e75874528806bfa53ddddd98b4da427d3a897" integrity sha1-ek51h0UogGv6U93d2YtNpCfTqJc= +react-ga4@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/react-ga4/-/react-ga4-2.1.0.tgz#56601f59d95c08466ebd6edfbf8dede55c4678f9" + integrity sha512-ZKS7PGNFqqMd3PJ6+C2Jtz/o1iU9ggiy8Y8nUeksgVuvNISbmrQtJiZNvC/TjDsqD0QlU5Wkgs7i+w9+OjHhhQ== + react-highlight-words@^0.16.0: version "0.16.0" resolved "https://registry.yarnpkg.com/react-highlight-words/-/react-highlight-words-0.16.0.tgz#4b4b9824e3d2b98789d3e3b3aedb5e961ae1b7cf"