How to Track Button Clicks in WordPress Without Google Tag Manager

Why Track Button Clicks?
Tracking button clicks helps you understand what actions visitors are taking. Whether it’s a “Buy Now”, “Download”, or “Contact Us” button, knowing the click-through rate gives valuable insights to improve your site and conversions.
You don’t need GTM — you can do it with Google Analytics 4 (GA4) and a bit of JavaScript.
Step 1: Ensure Google Analytics 4 Is Installed
Before anything else, make sure GA4 is active on your site. If not, check this tutorial: Set up Google Analytics 4.
If you’re not using a plugin, add the GA4 global site tag manually in your <head>:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
</script>
Step 2: Add a Custom JavaScript Tracker for Button Clicks
You can track button clicks by using GA4’s gtag('event') API. Example:
// Add this inside a <script> tag or enqueue it via functions.php
document.addEventListener('DOMContentLoaded', function () {
const trackableButtons = document.querySelectorAll('.track-button');
trackableButtons.forEach(button => {
button.addEventListener('click', function () {
gtag('event', 'button_click', {
'event_category': 'engagement',
'event_label': button.innerText || 'Unnamed Button',
'value': 1
});
});
});
});
This sends a custom event to GA4 whenever a button with the class .track-button is clicked.
Step 3: Add the Class to Your Buttons
Now, simply add class="track-button" to any button you want to track:
<a href="/contact" class="track-button btn">Contact Us</a>
You can use this with <button> elements or styled links — both work!
Step 4: View Click Data in Google Analytics 4
Go to your GA4 dashboard:
- Reports > Engagement > Events
- Look for the event name:
button_click
From there, you can view labels (button texts), total clicks, and engagement time.
Bonus: Track Specific Buttons with Unique Labels
Want to track different buttons separately? Use data-label attributes:
<a href="/download" class="track-button" data-label="Download Guide">Download</a>
Update your JS to support it:
gtag('event', 'button_click', {
'event_category': 'engagement',
'event_label': button.dataset.label || button.innerText,
'value': 1
});
Conclusion
You don’t need Google Tag Manager to track button clicks on your WordPress site. With a few lines of JavaScript and a GA4 property, you can send custom click events and monitor user interactions effectively — all while keeping your site lightweight.