Tracking Events

Chapter 4:

Step 5 - Send Custom Events

You can use the Link component to send custom events to Google Analytics when users interact with links.

import { Link } from '@pro/analytics/Link'

<Link
  href="/contact"
  eventData={{
    event: 'click',
    category: 'Navigation',
    action: 'Click Contact',
    label: 'Contact Us',
    value: 1,
  }}
>
  Contact Us
</Link>
  • When the link is clicked, it sends a custom event (gtag('event', ...)) to Google Analytics.

  • You can customize the event details, such as category, action, and label.

Additional Utility Functions:

  • sendAnalyticsEvent: Manually sends a custom event.

  • pageview: Tracks page views.

  • acceptCookies: Updates consent to enable analytics.

Last updated