Sub topic 13
When to Replace Enhanced Measurement with Custom Events
This chapter assumes you have read the earlier chapters on each enhanced measurement event. You should know the GA4 event and parameter model, be able to open a web data stream in Admin, and be comfortable reading short JavaScript. The code examples assume the Google tag (gtag.js) is already on the page, so gtag() is defined.
Enhanced measurement is a good default, but it is a fixed set of behaviors that you can only switch on or off. Sooner or later a report needs something the defaults cannot give you. This chapter covers how to recognize that point and how to move to custom events without creating duplicate data.
What you can and cannot change
Enhanced measurement gives you very few controls:
- Each event category has a toggle in the web data stream settings.
- Site search lets you edit the query parameter names and choose whether to strip query parameters from page URLs.
- Page changes based on browser history events can be switched on or off.
- You cannot change the event names, the parameters they carry, the scroll threshold, the list of file extensions, or which elements count as a form.
Everything else is fixed, so you need a custom event whenever one of those fixed behaviors gets in the way. A custom event is any event you send yourself with gtag('event', ...) or through a Google Tag Manager (GTM) tag. GA4 treats it exactly like an automatically collected event, so you can register its parameters as custom dimensions and mark it as a key event.
Signals that enhanced measurement is not enough
These are the usual reasons teams move to custom events.
| Symptom | Why enhanced measurement fails | Typical fix |
|---|---|---|
| You need scroll depth at 25%, 50% and 75% | `scroll` fires once, at 90% | Custom `scroll_depth` event |
| The `click` event fires on every outbound link, but you care about one button | The event is broad and has no way to filter by element | Custom `cta_click` on specific elements |
| A form submits with `fetch()` and no page reload | `form_submit` depends on the browser's native submit behavior and may not fire, or may fire when validation fails | Custom event after the server confirms success |
| Downloads are served from a URL with no file extension | The extension list is fixed | Custom `file_download`-style event with your own name |
| A video player is not YouTube, or the YouTube embed lacks `enablejsapi=1` | Video events only work for supported YouTube embeds | Custom events from the player's API |
| Site search results load via JavaScript without a query parameter in the URL | `view_search_results` is derived from URL parameters | Custom `search` event with the term from your code |
| You need business context, such as plan type or product ID | Enhanced events carry only fixed parameters | Custom event with your own parameters |
If a symptom is not on this list, first check that the problem is not a configuration mistake. A missing enablejsapi=1 or a misspelled site search parameter is much cheaper to fix than a custom implementation.
A decision flow
Work through the questions in this order. The aim is to write the least custom code that gives you the data you need.
The two custom paths differ in an important way.
- Supplement keeps the built-in event and adds a new one under a different name. This is the safest choice because existing reports do not change.
- Replace turns the toggle off and sends your own event, possibly under the same name. This is cleaner for long-term reporting but changes historical comparisons and needs more care.
Supplementing: use a different event name
When you add a custom event beside an enhanced one, give it a name that does not collide with the built-in name. If you send a custom event called scroll with different parameters, GA4 will store both versions under one event name. Reports then mix 90% scrolls with your own thresholds, and the percent_scrolled values become hard to interpret.
The following example reports 25%, 50% and 75% scroll depth under scroll_depth. The built-in scroll event still fires at 90%, so you get the complete range of depths without a name collision.
const thresholds = [25, 50, 75];
const fired = new Set();
window.addEventListener('scroll', () => {
const doc = document.documentElement;
const scrollable = doc.scrollHeight - doc.clientHeight;
if (scrollable <= 0) return;
const percent = (window.scrollY / scrollable) * 100;
thresholds.forEach((t) => {
if (percent >= t && !fired.has(t)) {
fired.add(t);
gtag('event', 'scroll_depth', { percent_scrolled: t });
}
});
}, { passive: true });Three details in this code matter:
- The
firedset makes each threshold report once per page load. Without it, the event would fire on every scroll tick after the threshold is passed. - The check for
scrollable <= 0avoids dividing by zero on pages that fit in the window. - The
{ passive: true }option tells the browser the handler will not block scrolling, which keeps pages smooth.
The parameter name percent_scrolled is reused deliberately so the value is familiar, but because the event name is different, the two datasets stay separate. To use the parameter in a report, register it as an event-scoped custom dimension. Note that percent_scrolled may already be registered for the built-in event, and one registration covers every event that sends that parameter.
Replacing: narrow a broad event
The built-in outbound click event fires for every link that leaves your domain. If the question is "did people click the pricing button," that event is too coarse. A targeted custom event gives you a clear name and only the parameters you want.
document.querySelectorAll('a[data-track="pricing-cta"]').forEach((link) => {
link.addEventListener('click', () => {
gtag('event', 'cta_click', {
link_text: link.textContent.trim(),
link_url: link.href
});
});
});This approach uses a data-track attribute as a contract between the markup and the analytics code. Designers can change classes and IDs freely, and the tracking keeps working as long as the attribute stays. If this link goes to another domain, the built-in click event will still fire too. That is usually fine, because the two events answer different questions. If you want to stop the built-in event, you must turn off the Outbound clicks toggle for the whole stream. Then you take on responsibility for tracking every outbound link you care about.
Replacing: forms that do not reload the page
form_start and form_submit are triggered by browser behavior. Many modern forms are submitted by JavaScript, and the page never reloads. In that case form_submit may not fire, or it may fire when the user clicks submit even though validation failed. The most reliable signal is the server's response.
const form = document.querySelector('#newsletter-form');
form.addEventListener('submit', async (event) => {
event.preventDefault();
const response = await fetch(form.action, {
method: 'POST',
body: new FormData(form)
});
if (response.ok) {
gtag('event', 'newsletter_signup', {
form_id: form.id,
form_destination: form.action
});
}
});This event fires only when the server accepts the submission. Treat it as the real conversion, and mark newsletter_signup as a key event instead of form_submit. You can leave the Form interactions toggle on, but do not use form_submit for conversion counts on this form.
Avoiding duplicate events
Duplicates are the most common failure when moving to custom events. They come from a few sources:
- Same event from two places. You keep the toggle on and also send a custom event with the same name, for example
file_downloadfrom both enhanced measurement and a GTM tag. - Two tags on the page. A hard-coded gtag.js snippet and GTM both send events to the same measurement ID.
- Single-page applications. A custom
page_viewis sent on route changes while "Page changes based on browser history events" is also on.
The rule to follow is that each interaction must have one owner. Before you add a custom event, decide which of these applies:
- The built-in event stays and is the only source. Do not send a custom event with the same name.
- The custom event replaces the built-in one. Turn off the matching toggle, or the whole feature, in the data stream first.
- Both exist, but under different names.
Event limits to keep in mind
Custom events use the same quotas as automatically collected ones. Standard properties allow a limited number of distinct event names, and each event can send a limited number of parameters. Custom dimensions are limited too, and each one must be registered before the parameter appears in standard reports and Explorations. A good naming scheme helps:
- Use lowercase snakecase, such as `ctaclick`, to match GA4's own style.
- Make names describe the action, not the page, so one event can be reused on many pages.
- Put the page-specific detail in a parameter instead of creating many event names. For example, one
cta_clickevent with alink_textparameter is better thanpricing_cta_click,demo_cta_clickandsignup_cta_click. - Avoid names reserved by Google, such as those starting with
ga_,firebase_orgoogle_.
Testing the change
After any change from enhanced to custom events, verify the result before relying on the data.
- Enable debug mode with
gtag('config', 'G-XXXXXXXXXX', { debug_mode: true });, replacing the ID with your own, or use Tag Assistant preview. - Open DebugView in GA4 Admin and perform the interaction once.
- Confirm that exactly one event appears for the interaction, with the expected name and parameters.
- If you replaced a built-in event, confirm the old event no longer appears.
- Register any new parameters as custom dimensions. They typically take up to a day to show in standard reports, but they appear in DebugView immediately.
- Mark the event as a key event if it represents a conversion.
Cost and maintenance trade-offs
Custom events give you precision, but they are code you own. Weigh these points before replacing a built-in event:
- Built-in events need no deployment and no developer time. Custom events need both.
- Built-in event names and parameters are known to everyone who uses GA4. Custom ones need documentation.
- Custom events can break when the page markup changes. Built-in events are less sensitive to this, though they are not immune.
- Custom events allow server-confirmed conversions, business parameters and exact thresholds, which built-in events cannot offer.
A sensible rule is to start with enhanced measurement, record the gaps you actually hit, and add custom events only for the interactions that drive decisions.
Exercise
Your site has a checkout form that submits with fetch() and shows a confirmation message without reloading. The Form interactions toggle is on, and your report shows many more form_submit events than completed orders. What should you do, and how do you avoid duplicate or misleading data?
Show answer
Send a custom event, such as checkoutcomplete, only after the server returns a successful response, and mark that event as a key event instead of formsubmit. Use a name that is different from formsubmit so the two do not mix. You can leave the Form interactions toggle on if you still want to measure formstart and attempted submits, but do not count formsubmit as an order. Check in DebugView that one order produces exactly one checkoutcomplete event.
Exercise
You want 25%, 50% and 75% scroll depth on article pages while keeping the built-in 90% scroll event. Why should the custom event not be called scroll, and which parameter must you register to see its values in reports?
Show answer
A custom event named scroll would share its name with the built-in event, so reports would mix 90% scrolls with your other thresholds. Use a different name such as scrolldepth. To see the value in standard reports, register percentscrolled as an event-scoped custom dimension. If it is already registered for the built-in event, the same registration also covers scroll_depth.