From c63f97cdb87f45647a7930a023613664c1550129 Mon Sep 17 00:00:00 2001 From: lis-dev Date: Wed, 24 Nov 2021 15:11:32 +0200 Subject: [PATCH] add google tag manager for main page --- .env.dist | 1 + package.json | 1 + src/index.tsx | 6 ++++++ yarn.lock | 5 +++++ 4 files changed, 13 insertions(+) diff --git a/.env.dist b/.env.dist index 8ba7888..6bd0e1d 100644 --- a/.env.dist +++ b/.env.dist @@ -1,2 +1,3 @@ REACT_APP_QUIZ_SERVER_URL=https://lis-dev.github.io/big5-data REACT_APP_DEFAULT_LANG=en +REACT_APP_GTM_ID= diff --git a/package.json b/package.json index 4e3181c..7e5a5e2 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "kutty": "^0.5.2", "react": "^17.0.2", "react-dom": "^17.0.2", + "react-ga4": "^1.4.1", "react-scripts": "^4.0.3", "typescript": "^4.1.2", "valtio": "^1.2.6", diff --git a/src/index.tsx b/src/index.tsx index 639dd95..49c94b7 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,6 +5,12 @@ import App from './App' import reportWebVitals from './reportWebVitals' import { Base } from './components/Base' import { ErrorBoundary } from './components/ErrorBoundary' +import ReactGA from 'react-ga4' + +if (process.env.REACT_APP_GTM_ID) { + ReactGA.initialize(process.env.REACT_APP_GTM_ID) + ReactGA.send('pageview') +} ReactDOM.render( diff --git a/yarn.lock b/yarn.lock index bce4ff5..d06ba20 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9406,6 +9406,11 @@ react-error-overlay@^6.0.9: resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.9.tgz#3c743010c9359608c375ecd6bc76f35d93995b0a" integrity sha512-nQTTcUu+ATDbrSD1BZHr5kgSD4oF8OFjxun8uAaL8RwPBacGBNPf/yAuVVdx17N8XNzRDMrZ9XcKZHCjPW+9ew== +react-ga4@^1.4.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/react-ga4/-/react-ga4-1.4.1.tgz#6ee2a2db115ed235b2f2092bc746b4eeeca9e206" + integrity sha512-ioBMEIxd4ePw4YtaloTUgqhQGqz5ebDdC4slEpLgy2sLx1LuZBC9iYCwDymTXzcntw6K1dHX183ulP32nNdG7w== + react-is@^16.8.1: version "16.13.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"