How to Track Button Clicks in GA4 with Google Tag Manager
Step-by-step guide to tracking button clicks in GA4 using GTM click triggers, CSS selectors, and custom event tags. Includes code examples.
Tracking button clicks tells you which CTAs are working and which are being ignored. Here is how to set it up in GTM without touching your website code.
Step 1: Enable Click Variables in GTM
- Go to Variables > Configure
- Enable all built-in Click variables:
- - Click Element
- - Click Classes
- - Click ID
- - Click Target
- - Click URL
- - Click Text
These variables capture data about whatever the user clicks.
Step 2: Create a Click Trigger
Option A: Track All Clicks (for discovery)
- Triggers > New > Click - All Elements
- Fire on: All Clicks
- Save
Use this temporarily with GTM Preview to see what click data is available, then narrow it down.
Option B: Track Specific Buttons by CSS Selector
- Triggers > New > Click - All Elements
- Fire on: Some Clicks
- Condition: Click Element > matches CSS selector > `button.cta-primary`
Common CSS selectors:
- button.cta-primary — buttons with class "cta-primary"
- a[href="/pricing"] — links to the pricing page
- #signup-btn — element with ID "signup-btn"
- [data-track="cta"] — elements with a data attribute
Option C: Track Links to Specific URLs
- Triggers > New > Click - Just Links
- Fire on: Some Link Clicks
- Condition: Click URL > contains > `/demo`
Step 3: Create the GA4 Event Tag
- Tags > New > GA4 Event
- Event name: `cta_click`
- Parameters:
- - `button_text`: `{{Click Text}}`
- - `button_url`: `{{Click URL}}`
- - `page_path`: `{{Page Path}}`
- Trigger: your click trigger from Step 2
Step 4: Test in Preview Mode
- Click Preview in GTM
- Open your site
- Click the button you are tracking
- In the Tag Assistant panel, verify:
- - Your trigger fired
- - Your GA4 tag fired
- - Event parameters have the correct values
- Check GA4 DebugView for the `cta_click` event
Advanced: Data Attributes for Clean Tracking
Instead of relying on CSS classes (which change during redesigns), add data attributes to your HTML:
<button data-track="cta" data-track-name="Start Trial" data-track-location="hero"> Start your trial </button>html
In GTM, create a Data Layer Variable or DOM Element variable to read data-track-name and use it as a parameter.
This approach survives CSS refactors and gives you explicit control over tracking labels.
Making It a Key Event
If a button click represents a meaningful business action (e.g., "Book a Demo" button), mark it as a key event:
- GA4 Admin > Key events > New key event
- Event name: `cta_click`
Or create a filtered key event if you only want specific CTAs:
1. Admin > Events > Create event
2. Name: demo_cta_click
3. Conditions: event_name equals cta_click AND button_text contains Demo
Not sure if your click tracking is working? Audit your GA4 setup →
Check your GA4 implementation
Run a free AI-powered audit to see how your tracking stacks up.
Start Free Audit