Skip to content

Commit

Permalink
feat(web): Improve event tracking
Browse files Browse the repository at this point in the history
Improves processing tracking events, to make them more reliable to page
navigations.
  • Loading branch information
langri-sha committed Jun 18, 2024
1 parent 862b9ad commit 222de81
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions apps/web/src/components/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ export const Link: React.FC<LinkProps> = ({
}) => {
// Use the 'useCallback' hook for optimized event handler
const handleClick: React.MouseEventHandler<HTMLAnchorElement> =
React.useCallback(() => {
gtag('event', eventAction, {
event_category: eventCategory,
event_label: eventLabel,
})
}, [eventCategory, eventAction, eventLabel])
React.useCallback(
(event) => {
event.preventDefault()

gtag('event', eventAction, {
event_category: eventCategory,
event_label: eventLabel,

event_callback: () => {
window.location.href = props.href
},
event_timeout: 2000,
})
},
[eventCategory, eventAction, eventLabel],
)

return (
<a {...props} onClick={handleClick}>
Expand Down

0 comments on commit 222de81

Please sign in to comment.