Engagement
How to track button clicks in Google Analytics 4, with or without Tag Manager
GA4 does not track button clicks by default. Three ways to add them: a gtag call, a Tag Manager trigger, or one HTML attribute, with the steps for each.
The CrispStats team · · 7 min read
In short
Google Analytics 4 records outbound link clicks and file downloads automatically, but not clicks on your own buttons. To track one, send a custom event: with a gtag call in your code, or with a Tag Manager click trigger and a GA4 event tag, then register any parameters as custom dimensions to see them in reports. In CrispStats, a single data-cs-event attribute on the button does the same job.
On this page · 7 sections
Sections
Clicks on a pricing toggle, a Start trial button or a Book a demo link are often the most useful signals on a page, and they are exactly what a default GA4 setup does not see. This guide covers what GA4 already records, then three ways to add the rest, with what each costs you in setup and upkeep.
What clicks does GA4 track automatically?
With enhanced measurement on, GA4 sends a few click-related events without code. None of them is a click on your own buttons:
| Event | Fires when | Covers button clicks? |
|---|---|---|
click (outbound) | A visitor clicks a link to another domain | Only if the button is a link that leaves your site |
file_download | A visitor clicks a link to a file such as a PDF or ZIP | Only for download links |
form_start, form_submit | A visitor first interacts with a form, or submits it | Only the form’s submit, not other buttons |
scroll | A visitor reaches 90% of the page | No |
For a Start trial button that opens a page on your own site, none of these fires, so you need a custom event. If scroll is the signal you care about, scroll depth tracking covers going beyond the single 90% event.
Method 1: send the event from your code with gtag
If the Google tag is already on your page, call gtag when the button is clicked. Google’s events guide uses the same form: the command, an event name and an object of parameters.
<button id="start-trial">Start trial</button><script> document.getElementById("start-trial").addEventListener("click", function () { gtag("event", "start_trial_click", { button_location: "pricing_hero" }); });</script>Name events in lowercase with underscores, and keep within GA4’s collection limits: event names and parameter names up to 40 characters, parameter values up to 100 characters, and up to 25 parameters per event on standard properties.
- Good for: sites where a developer ships changes anyway; tracking that should survive redesigns, because it lives next to the button’s code.
- Cost: every new event needs a code change and a release.
Method 2: use Google Tag Manager
If GA4 runs through Tag Manager, you can add click tracking without touching the site’s code. If you are deciding whether you need Tag Manager at all, read Google Tag Manager vs Google Analytics first.
- Switch on the click variables. In Variables, select Configure and tick the built-in click variables: Click Element, Click Classes, Click ID, Click URL and Click Text.
- Find something that identifies the button. Open Preview, click the button on your site, select the click event in the debug panel and look at the Variables tab. An id such as
start-trialis best; a stable class or the button text will do. - Create the trigger. In Triggers, add a click trigger of type All Elements, choose Some Clicks, and set the condition, for example Click ID equals
start-trial. Use Just Links instead if the button is an<a>element and you want the Wait for Tags option. - Create the tag. In Tags, add a Google Analytics event tag. Enter your measurement ID, the event name
start_trial_click, and a parameterbutton_locationwith the valuepricing_heroor a variable. Attach the trigger. - Test it. In Preview, click the button and confirm the tag fired once. Then check GA4’s realtime report or DebugView for the event.
- Publish the container version with a short description of the change.
The child element problem
With All Elements, Click Element is the innermost thing clicked. If the button contains an icon or a <span>, a click on the icon has no id, and a trigger on Click ID misses it. Use the condition Click Element matches CSS selector with a selector that covers the button and everything inside it:
#start-trial, #start-trial *Then: make the click visible in reports
The event is collected from the first click, but a few steps decide whether anyone can use it.
- Register parameters as custom dimensions. In Admin, open Custom definitions and create an event-scoped dimension for
button_location. Google notes it takes 24 to 48 hours before you can report on a new custom dimension. - Mark it as a [key event](/glossary/key-event) if it is a goal. If the click is a conversion you care about, mark the event as a key event so it appears in conversion and attribution reports.
- Find it. Open Reports, Engagement, Events and select
start_trial_click, or build an exploration with the event name and your new dimension.
A worked example: click-through rate for a button
Counting clicks is only half the answer. Divide them by the views of the page the button is on:
| Page | Pageviews | start_trial_click events | Click rate |
|---|---|---|---|
| Pricing | 4,000 | 280 | 7.0% |
| Home | 12,000 | 360 | 3.0% |
| Features | 3,000 | 45 | 1.5% |
The home page sends the most clicks, but the pricing page converts attention into clicks more than twice as well. If you count unique visitors who clicked instead of events, repeat clicks stop inflating the rate. The conversion rate calculator does the same sum for any goal.
Which method should you use?
| Row | gtag in code | Tag Manager | HTML attribute |
|---|---|---|---|
| Needs a code release | Yes | No, after Tag Manager is installed | Yes, but only markup |
| Survives a redesign | Yes, if the code moves with the button | Only if the id or class stays | Yes, the attribute moves with the button |
| Who can add it | Developers | Anyone with container access | Anyone who edits the page template |
| Number of steps | One | Variables, trigger, tag, preview, publish | One |
| Typed values (numbers, booleans) | Yes | Yes | Strings only |
How to track button clicks in CrispStats
CrispStats takes the third route. Add a data-cs-event attribute to the element, and every click on it, or on anything inside it, is sent as a custom event with that name. Each data-cs-prop-* attribute on the same element becomes a property:
<button data-cs-event="start trial" data-cs-prop-location="pricing hero"> Start trial</button>There is no trigger and no tag to set up, and the child element problem does not arise: the script looks for the closest element with the attribute, starting from what was clicked. It listens in the capture phase, so the click still counts when a handler stops propagation, and it sends with sendBeacon, so a link that leaves the page still reports. Elements rendered later by a framework work without extra setup.
Attribute values are always strings, and only clicks count (a key press that activates a button fires a click and is included). For numbers, booleans or events that are not clicks, call crispstats("start trial", { plan: "growth" }) from your code. Events appear under Events in the dashboard within seconds, with no custom dimension to register, and you can use them as steps in funnels or as goals; conversion funnel analysis shows how to read a click as one step of many. The full rules are in the declarative events docs, and the attribute works the same if you load the script through Tag Manager.