Gtm
Introduction
What Are GTM Events?
In the context of websites and applications, Google Tag Manager (GTM) events are specific user interactions or system actions that we want to track. These interactions help us understand user behavior, engagement, and system performance.
Common Examples of Events:
- Button clicks
- Video plays
- Page views
- Scroll activity
- Form submissions
- Form interactions (e.g., focus, blur, input)
- Link clicks
- File downloads
- Errors or exceptions
Basically, anything users do on a page or anything significant that happens in the system can be tracked as an event.
Why Use GTM Events?
GTM allows us to listen for these events and use them to trigger tags—snippets of code that send data to external platforms.
This could include:
- Google Analytics – for tracking behavior
- Facebook Pixel – for ads conversions
- Datadog – for monitoring and performance (which we're currently using)
By triggering these tags through events, we can send accurate, consistent data to the right tools without touching code every time we need to make an update.
How We Implement Events
To make our event tracking clean and maintainable, we follow a standardized approach.
Our Approach:
- We wrap all event-logging logic inside a single utility method.
- This method is responsible for:
- Structuring event data
- Calling internal logging services (e.g., GTM, Datadog)
- Ensuring consistency across all events
- Developers only need to pass the relevant parameters (event name, category, action, label, etc.) once.
- The utility handles everything else behind the scenes.
File Location: /utils/event-logger.utils.ts
Benefits of This Setup:
- DRY (Don’t Repeat Yourself): Avoids duplicating logic for every new event
- Consistency: Ensures uniform structure for all events
- Scalability: Easily extend to other platforms (e.g., GA4, Segment, etc.)
- Maintainability: Update logic in one place when needed