Commit 620e846 1 parent 205a9cd commit 620e846 Copy full SHA for 620e846
File tree 3 files changed +32
-1
lines changed
3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 9
9
"@types/react-dom" : " ^18.0.0" ,
10
10
"react" : " ^18.2.0" ,
11
11
"react-dom" : " ^18.2.0" ,
12
+ "react-ga4" : " ^2.1.0" ,
12
13
"react-hotkeys-hook" : " ^4.5.0" ,
13
14
"react-router-dom" : " ^6.22.1" ,
14
15
"react-select" : " ^5.8.0" ,
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import './index.css'
4
4
import App from './App'
5
5
import reportWebVitals from './reportWebVitals'
6
6
import { BrowserRouter } from 'react-router-dom'
7
+ import { Metric } from 'web-vitals'
8
+ import ReactGA from 'react-ga4'
7
9
8
10
const root = ReactDOM . createRoot (
9
11
document . getElementById ( 'root' ) as HTMLElement
@@ -16,7 +18,30 @@ root.render(
16
18
</ React . StrictMode >
17
19
)
18
20
21
+ ReactGA . initialize ( [
22
+ {
23
+ trackingId : 'G-XEN77GP035'
24
+ }
25
+ ] )
26
+
27
+ const getEventValueFromMetric = ( metric : Metric ) => {
28
+ if ( metric . name === 'CLS' ) {
29
+ return Math . round ( metric . value * 1000 )
30
+ }
31
+ return Math . round ( metric . value )
32
+ }
33
+
34
+ const reportHandler = ( metric : Metric ) => {
35
+ ReactGA . event ( {
36
+ category : 'Web Vitals' ,
37
+ action : metric . name ,
38
+ value : getEventValueFromMetric ( metric ) ,
39
+ label : metric . id ,
40
+ nonInteraction : true
41
+ } )
42
+ }
43
+
19
44
// If you want to start measuring performance in your app, pass a function
20
45
// to log results (for example: reportWebVitals(console.log))
21
46
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
22
- reportWebVitals ( )
47
+ reportWebVitals ( reportHandler )
Original file line number Diff line number Diff line change @@ -8689,6 +8689,11 @@ react-error-overlay@^6.0.11:
8689
8689
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.11.tgz#92835de5841c5cf08ba00ddd2d677b6d17ff9adb"
8690
8690
integrity sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg==
8691
8691
8692
+ react-ga4@^2.1.0 :
8693
+ version "2.1.0"
8694
+ resolved "https://registry.yarnpkg.com/react-ga4/-/react-ga4-2.1.0.tgz#56601f59d95c08466ebd6edfbf8dede55c4678f9"
8695
+ integrity sha512-ZKS7PGNFqqMd3PJ6+C2Jtz/o1iU9ggiy8Y8nUeksgVuvNISbmrQtJiZNvC/TjDsqD0QlU5Wkgs7i+w9+OjHhhQ==
8696
+
8692
8697
react-hotkeys-hook@^4.5.0 :
8693
8698
version "4.5.0"
8694
8699
resolved "https://registry.yarnpkg.com/react-hotkeys-hook/-/react-hotkeys-hook-4.5.0.tgz#807b389b15256daf6a813a1ec09e6698064fe97f"
You can’t perform that action at this time.
0 commit comments