Button click tracking is one of the most common GTM tasks — and one of the most commonly done wrong. A carelessly configured Click trigger can fire on every link on the page, inflating your conversion counts and sending garbage data to your analytics platform. This guide shows you how to do it precisely.
Enable Built-In Click Variables First
Before you create any Click trigger, go to Variables → Configure and enable the following Click variables:
- Click Element — the DOM element that was clicked
- Click Classes — CSS classes on the clicked element
- Click ID — the ID attribute of the clicked element
- Click Target — the link target (e.g.
_blank) - Click Text — the visible text of the clicked element
- Click URL — the href of a clicked link
These variables are populated at the moment of each click. Without enabling them, your trigger conditions won't have anything to match against.
Method 1: Track a Button by CSS Class or ID
This is the cleanest approach when your button has a stable class or ID. Go to Triggers → New → Click – All Elements (not Just Links — buttons aren't anchor tags).
Set the trigger to fire on Some Clicks and add the condition:
- Click Classes contains
btn-cta
Or if the button has an ID:
- Click ID equals
get-started-button
Test this in Preview mode before publishing. Click the button and check the Click tab in the summary panel to confirm the trigger fired and the variable values look correct.
Method 2: Track by Click Text
When buttons don't have consistent classes or IDs — common on WordPress and Squarespace sites — you can match on the button's visible text:
- Click Text equals
Get a Free Quote
Be careful: this approach breaks if someone edits the button text. Also, Click Text is case-sensitive by default. Use contains rather than equals if there's any risk of variation.
Method 3: Track by Click URL (for Links)
For link clicks — nav items, text links, CTA links — use a Click – Just Links trigger instead of All Elements. This fires only on <a> tags and gives you access to the href:
- Click URL contains
/contact
This reliably tracks clicks to your contact page regardless of where the link appears.
Method 4: Use CSS Selectors for Complex Elements
Some buttons are nested inside complex HTML structures — an icon inside a span inside a div inside a button, for example. When you click the icon, GTM may record the click on the icon element, not the outer button, causing your CSS class condition to miss.
The fix: use the matches CSS selector condition with the Click Element variable:
- Click Element matches CSS selector
.cta-wrapper button
GTM will traverse the DOM tree upward from the clicked element looking for a match — so even if you click the icon inside the button, it finds the outer button. This is the most robust method for complex UIs.
Attaching a Tag to Your Click Trigger
Once your trigger is configured, attach it to a tag. For GA4:
- Create a new GA4 Event tag
- Event name:
button_click(or something more specific likecta_click) - Add event parameters:
button_text→{{Click Text}}button_url→{{Click URL}}page_path→{{Page Path}}
- Set the trigger to your click trigger
Publishing without those extra parameters is a common mistake — you'll know a click happened but not which button or where on the site it was clicked.
Debugging Click Tracking
GTM Preview Mode
Open Preview, navigate to your page, click the button, and look for a Click event in the left panel. Select it and check:
- Did your trigger fire? (green checkmark in the Tags tab)
- What did
{{Click Classes}},{{Click Text}},{{Click Element}}return?
The Element Isn't What You Think
If the trigger isn't firing, open the Variables tab for the click event and look at Click Element. You may be clicking a child element (an SVG icon, a <span>) rather than the button itself. Switch to a CSS selector condition that accounts for this.
Trigger Fires Too Broadly
If the trigger fires on clicks you don't intend, add additional conditions. For example, combine a CSS class match with a page path condition:
- Click Classes contains
btn-primary - Page Path equals
/pricing/
Common Mistakes to Avoid
- Using All Links trigger without conditions — this fires on every link click across your site
- Forgetting to enable Click variables — your conditions evaluate to undefined and may fire unexpectedly
- Not testing across devices — buttons sometimes behave differently on mobile, especially touch targets that overlap
- Tracking without parameters — a
button_clickevent with no context is almost useless for analysis
Conclusion
Precise button click tracking is foundational to understanding how users interact with your CTAs, navigation, and forms. The key is being specific with your trigger conditions and always verifying in Preview mode before publishing.
If you need reliable click tracking implemented across your entire site — including dynamic content and single-page applications — Adslytics can handle the full setup. Contact us to get started.
Need expert tracking setup?
Our Google Tag Manager experts have delivered 500+ tracking setups with a 98% success rate.
Get a Free Consultation →