Commit 11e595f 1 parent c8503bc commit 11e595f Copy full SHA for 11e595f
File tree 1 file changed +8
-6
lines changed
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { Metric } from 'web-vitals'
2
2
import ReactGA from 'react-ga4'
3
+ import { UaEventOptions } from 'react-ga4/types/ga4'
3
4
4
- const getAnalyticsId = ( ) => process . env . GOOGLE_ANALYTICS_TRACKING_ID
5
+ const analyticsId = process . env . GOOGLE_ANALYTICS_TRACKING_ID
5
6
const isDev = ( ) => process . env . NODE_ENV && process . env . NODE_ENV === 'development'
6
7
7
8
const getEventValueFromMetric = ( metric : Metric ) => {
@@ -12,28 +13,29 @@ const getEventValueFromMetric = (metric: Metric) => {
12
13
}
13
14
14
15
const reportHandler = ( metric : Metric ) => {
15
- const event = {
16
+ const event : UaEventOptions = {
16
17
category : 'Web Vitals' ,
17
18
action : metric . name ,
18
19
value : getEventValueFromMetric ( metric ) ,
19
20
label : metric . id ,
20
- nonInteraction : true
21
+ nonInteraction : true ,
22
+ transport : 'beacon'
21
23
}
22
24
23
25
if ( isDev ( ) ) {
24
26
console . debug ( `[web-vitals-dev] ${ event . action } : ${ event . value } ` , metric ) // eslint-disable-line no-console
25
27
}
26
28
27
- if ( getAnalyticsId ( ) ) {
29
+ if ( analyticsId ) {
28
30
ReactGA . event ( event )
29
31
}
30
32
}
31
33
32
34
const reportWebVitals = ( ) => {
33
- if ( getAnalyticsId ( ) ) {
35
+ if ( analyticsId ) {
34
36
ReactGA . initialize ( [
35
37
{
36
- trackingId : getAnalyticsId ( ) !
38
+ trackingId : analyticsId
37
39
}
38
40
] )
39
41
}
You can’t perform that action at this time.
0 commit comments