import { GOOGLE_TRACKING_ACTIONS, GOOGLE_TRACKING_CATEGORIES, GOOGLE_TRACKING_LABEL, GOOGLE_TRACKING_TRANSPORT, } from '../constants/googleTracking' import ReactGA from 'react-ga4' export const trackEventWithGA = ( category: GOOGLE_TRACKING_CATEGORIES, action: GOOGLE_TRACKING_ACTIONS, isActionSuccess: boolean = true, value: number = 0, nonInteraction: boolean = true, transport: GOOGLE_TRACKING_TRANSPORT = GOOGLE_TRACKING_TRANSPORT.XHR, ) => { const label = isActionSuccess ? GOOGLE_TRACKING_LABEL.SUCCESS : GOOGLE_TRACKING_LABEL.FAIL ReactGA.event({ category: category, action: action, label: `${category} ${label}`, // optional value: value, // optional, must be a number nonInteraction: nonInteraction, // optional, true/false transport: transport, // optional, beacon/xhr/image }) }