Skip to content

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.

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:

What clicks does GA4 track automatically?
EventFires whenCovers button clicks?
click (outbound)A visitor clicks a link to another domainOnly if the button is a link that leaves your site
file_downloadA visitor clicks a link to a file such as a PDF or ZIPOnly for download links
form_start, form_submitA visitor first interacts with a form, or submits itOnly the form’s submit, not other buttons
scrollA visitor reaches 90% of the pageNo

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.

  1. 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.
  2. 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-trial is best; a stable class or the button text will do.
  3. 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.
  4. Create the tag. In Tags, add a Google Analytics event tag. Enter your measurement ID, the event name start_trial_click, and a parameter button_location with the value pricing_hero or a variable. Attach the trigger.
  5. Test it. In Preview, click the button and confirm the tag fired once. Then check GA4’s realtime report or DebugView for the event.
  6. 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.

  1. 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.
  2. 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.
  3. 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:

A worked example: click-through rate for a button
PagePageviewsstart_trial_click eventsClick rate
Pricing4,0002807.0%
Home12,0003603.0%
Features3,000451.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?

Which method should you use?
Rowgtag in codeTag ManagerHTML attribute
Needs a code releaseYesNo, after Tag Manager is installedYes, but only markup
Survives a redesignYes, if the code moves with the buttonOnly if the id or class staysYes, the attribute moves with the button
Who can add itDevelopersAnyone with container accessAnyone who edits the page template
Number of stepsOneVariables, trigger, tag, preview, publishOne
Typed values (numbers, booleans)YesYesStrings 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.

Guide questions. Straight answers.

What people ask after reading this.

  • No. Enhanced measurement records outbound link clicks, file downloads, form starts and form submits, but not clicks on buttons that stay on your site. Those need a custom event sent with gtag or from Tag Manager.

  • Add a click listener to the button in your code and call gtag with the event command, an event name such as start_trial_click and any parameters. The event appears in realtime and DebugView, and in standard reports after processing.

  • Standard reports show events after processing, not instantly, and parameters only become reportable once you register them as custom dimensions, which Google says takes 24 to 48 hours. Check realtime or DebugView first to confirm the event is being sent at all.

  • Usually because the visitor clicked an icon or text inside the button, so the clicked element has no matching id or class. Use a CSS selector condition that matches the button and its children, for example the button's id followed by the same id with a space and an asterisk.

  • Track every click you want to analyse as an event. Mark only the few that represent a real goal, such as starting a trial or requesting a demo, as key events, so conversion and attribution reports stay meaningful.

Not answered here? Write to hello@crispstats.com

Go further

Free tools

Use cases

  • CrispStats for SaaS

    See which channels bring paying customers, where trials stall in the funnel, and how your app performs for real users, from one cookieless script.

  • CrispStats for ecommerce

    Tie orders to the campaign, page and source they came from, find where checkout loses people, and watch page speed, without cookies.

  • CrispStats for startups

    Funnels, retention, revenue attribution and uptime from the first day, on a price that stays small while you find your market.

Your traffic, crisp and clear

One script, no cookies, and every feature from the first day. Set up takes about as long as pasting a snippet.