Why track button clicks?
Page views tell you where users go. Button clicks tell you what they do. Knowing which buttons your users click most — and which ones they ignore — helps you understand what matters to your users and what doesn’t. Examples of things to learn from button tracking:- Which call-to-action button converts better — “Start Free Trial” or “Try Now”?
- Are users clicking the pricing page button or ignoring it?
- How many users click “Upgrade” but never complete the purchase?
The basic pattern
To track a button, you need to add anonClick action to it. If your button already has an action, just add track() inside it. If it doesn’t, add a new action.
Before:
components/PricingButton.jsx
components/PricingButton.jsx
- React / Next.js (JavaScript)
- React / Next.js (TypeScript)
- Vue 3
- Vanilla HTML
components/Hero.jsx
Adding context with properties
Always add alocation property so you know where in your app the button was clicked. Same button might exist in multiple places:
utils/analytics.js
Tracking navigation links
Links work the same way as buttons:- React / Next.js
- Vanilla HTML
components/Navbar.jsx
Real-world example — CTA buttons on a landing page
Recommended properties for button click events
| Property | Type | Description | Example |
|---|---|---|---|
location | string | Where on the page the button is | 'hero', 'navbar', 'footer' |
button | string | The button’s label text | 'Sign Up Free', 'Upgrade' |
page | string | Which page the user is on | 'landing', 'dashboard' |
variant | string | A/B test variant if applicable | 'variant_a', 'control' |
Naming your events
Use this pattern:[noun]_[action]
| Good | Bad |
|---|---|
signup_clicked | click |
pricing_button_clicked | buttonWasClicked |
upgrade_cta_clicked | btn1 |
demo_request_clicked | Pricing Button Click |