Track Button Clicks Without Google Tag Manager
Why skip Google Tag Manager
Google Tag Manager is a capable tool, but it is more than many small sites need. It adds a container script, a separate tag setup flow, and another place to debug when events do not fire. If your main goal is to know which buttons people click, a direct listener in your own code is easier to review and maintain.
Start with a data attribute
A stable naming convention keeps click tracking readable. Add a data attribute to each button or link you care about.
<button data-track-click="nav_signup">Sign up</button>
Then add one delegated listener near the end of your page or in your main JavaScript bundle.
document.addEventListener('click', function (event) {
const element = event.target.closest('[data-track-click]');
if (!element) return;
const name = element.getAttribute('data-track-click');
recordClick(name);
});
The listener catches clicks on the button itself or any child element. You do not need to attach a handler to every button.
Decide what to record
A click event is more useful with context. At minimum, record:
- click name
- current page path
- timestamp
- a visitor identifier if your analytics system supports one
Avoid recording the button text or other visible content unless you have a specific reason. The event name should be enough to tell you what happened.
Send the click somewhere useful
Keep the sending logic in one function so you can change analytics providers later.
function recordClick(name) {
console.log('click', { name: name, path: location.pathname });
// Replace with your analytics call or fetch to your own endpoint.
}
For a simple dashboard, you could POST events to your own backend. For a small site, a client-side analytics tool is often faster to set up.
Start with the three clicks that matter
Before instrumenting every button, list the actions that directly affect your business. For a small site, that might be:
- main navigation signup
- pricing page signup
- footer contact link
Tracking fewer events well is better than tracking fifty events loosely. Too many event names make reports hard to read and encourage you to ignore them.
Use click events for conversion steps
Click tracking is most valuable when it feeds a funnel. Track the small number of actions that matter, such as pricing_click, signup_click, and checkout_start. If your analytics tool supports funnels from events, you can see where people drop off.
A cookieless option with built-in click tracking
If you do not want to maintain your own listener, check whether your analytics script supports click tracking through a data attribute. For example, measuremy.site is a hosted cookieless tracker that sets no cookies and stores no personal data. It has a 30-day free trial with no card. You install it with one script tag:
<script defer src="https://a.measuremy.site/t.js" data-key="YOUR_KEY"></script>
Then mark a button like this:
<button data-measuremysite-event="signup_click">Sign up</button>
The script collects the click, and the dashboard shows it as an event. That removes the need to write and maintain your own listener.
Debug with the browser console
When you first add the listener, open the browser console and click a marked button. The console log should appear once. If it appears twice, you likely have two listeners. If it does not appear, check that the script runs after the DOM is available and that the attribute name matches exactly. This quick check catches most setup problems before they affect your reports.
Watch out for duplicate and missed clicks
If you add both a framework click handler and a global listener, a single click may be recorded twice. Choose one path per event. In React or Vue apps, a global document listener can also miss clicks when components stop propagation or render inside shadow DOM. For most small sites, the simple listener works. Test on a staging page before relying on the numbers.
Filter out your own clicks and bots
Internal testing can inflate a button's count. If possible, ignore your own IP or use a separate staging environment. Some bots click buttons while crawling forms, so consider filtering out impossible timing or known bot user agents. This keeps your conversion rates readable.
Keep event names stable
Event names such as signup_click should stay the same across weeks. Keep a short list in your README or code comments. Stable names let you compare this week with last week without rebuilding reports.
You do not need Google Tag Manager to learn which buttons matter. A data attribute and one listener can cover many small sites, and a cookieless analytics script with built-in click tracking can remove even that code. Whether you use a custom listener or a tool like measuremy.site, keep event names stable, record only what you need, and test that clicks appear in your reports before you rely on them.
See it on your own site
measuremy.site is cookieless analytics your coding agent can read. 30-day free trial, no card. Plans from $9/month.
Start free trial See the live demoAdd measuremy.site analytics to this project: connect the measuremy.site MCP server at https://a.measuremy.site/mcp for all my projects (claude mcp add --scope user; it signs in with OAuth, no key, and one sign-in covers every site), then tell me how to sign in. Details: measuremy.site/llms.txt
Free tools
- Analytics tag checker: Which analytics and pixels a site runs, plus duplicate and broken tags.
- Free UTM link builder: Add utm_source, medium and campaign to any link.
- Website traffic checker: A site's popularity rank and estimated monthly visits.
More from the blog
- How to calculate your website conversion rate, and what to compare it to
- Is my A/B test result significant? A plain-English guide with a worked example
- What is bounce rate, how is it calculated, and is yours a problem?
- How to add a visitor counter to your website or GitHub README
- How much traffic does a website get? How to estimate any site's visits
- How to track QR code scans: count them, and see which poster worked
- How to see how many people clicked your link (without a paid shortener)
- How to check if your Google Analytics 4 tag is installed (and only counting once)
- Why GA4 shows your campaign traffic as Unassigned (and how to fix the links)
- Does your redirect keep your UTM tags? How to check before a campaign goes out
- How I built a self-hosted analytics MCP server on Cloudflare Workers and D1
- UTM tracking explained: what the parameters mean and how to use them
- Conversion funnel analysis for small sites: a practical guide
- Sudden drop in website traffic? A checklist for finding the cause
- What is an MCP server? A plain-English guide for people who run websites
- Website Data Analytics for Owners: A Practical Guide
- Vanity Metrics vs Useful Metrics: What to Track
- How to Compare Cookieless Website Tracking Tools
- Why Your Analytics Numbers Differ Between Tools
- When GA4 Is Too Much for a Small Website
- How to keep historical data when switching analytics tools
- How to give an AI agent read-only access to your analytics
- Why developers are connecting agents to production data
- How to recover from a sudden traffic drop
- Website analytics for indie hackers: what to watch and what to ignore
- Direct Traffic Explained: Why So Much Is Unknown
- Why a high bounce rate is not always bad
- High bounce rate: 8 causes and practical fixes
- How to Set Up Traffic Alerts for Sudden Drops
- How to Track Traffic From a Podcast
- How to measure the return on a paid ad campaign
- How to use analytics to decide what to write next
- How the Model Context Protocol Works
- Track File Downloads Without Guesswork
- Adding analytics to a Next.js app without slowing it down
- Core Web Vitals and Traffic: Is There a Link?
- Analytics After Cookies: What Actually Changes
- GDPR and website analytics: a practical guide for small sites
- How to Compare Website Analytics Tools by Privacy
- GA4 Events Explained for Beginners
- How to measure a newsletter send with UTM links
- How to track Hacker News traffic
- Adding Analytics to a Framer Site
- How to ask your coding agent about your analytics
- What Is Bounce Rate and How Is It Calculated?
- A practical website analytics retention policy
- Map your site's funnel from first visit to signup
- What Is a Good Bounce Rate?
- How to automate a weekly traffic report
- A Practical Privacy-Friendly Analytics Checklist
- Adding an MCP server to Claude Code
- How long should you keep analytics data?
- How to Build a Small MCP Server That Actually Helps
- How to Find the Biggest Drop Off in a Funnel
- What Is the Urchin Tracking Module?
- What Microsoft MCP servers actually do
- UTM parameters for email newsletters
- How to track the results of a social media post without cookies
- How to track traffic from a GitHub README
- How to measure a product launch without guessing