| export interface GAEvent { |
| hitType: "event"; |
| eventCategory: string; |
| eventAction: string; |
| eventLabel?: string; |
| eventValue?: number; |
| } |
|
|
| |
| export function sendAnalyticsEvent({ |
| eventCategory, |
| eventAction, |
| eventLabel, |
| eventValue, |
| }: Omit<GAEvent, "hitType">): void { |
| |
| const event: GAEvent = { |
| hitType: "event", |
| eventCategory, |
| eventAction, |
| }; |
| |
| if (eventLabel) { |
| event.eventLabel = eventLabel; |
| } |
| if (eventValue) { |
| event.eventValue = eventValue; |
| } |
|
|
| |
| if (!!window?.gtag && typeof window?.gtag === "function") { |
| |
| window?.gtag("event", eventAction, { |
| event_category: event.eventCategory, |
| event_label: event.eventLabel, |
| value: event.eventValue, |
| }); |
| } |
| } |
|
|