# How to track button clicks

The CrispStats team · Published 2026-11-23 · Updated 2026-11-29

**TL;DR:** Google Analytics 4 records outbound link clicks and file downloads automatically, but not clicks on your own buttons. To track one, send a custom event: with a gtag call in your code, or with a Tag Manager click trigger and a GA4 event tag, then register any parameters as custom dimensions to see them in reports. In CrispStats, a single `data-cs-event` attribute on the button does the same job.

Clicks on a pricing toggle, a Start trial button or a Book a demo link are often the most useful signals on a page, and they are exactly what a default GA4 setup does not see. This guide covers what GA4 already records, then three ways to add the rest, with what each costs you in setup and upkeep.

## What clicks does GA4 track automatically?

With [enhanced measurement](https://support.google.com/analytics/answer/9216061) on, GA4 sends a few click-related events without code. None of them is a click on your own buttons:

| Event | Fires when | Covers button clicks? |
| --- | --- | --- |
| `click` (outbound) | A visitor clicks a link to another domain | Only if the button is a link that leaves your site |
| `file_download` | A visitor clicks a link to a file such as a PDF or ZIP | Only for download links |
| `form_start`, `form_submit` | A visitor first interacts with a form, or submits it | Only the form's submit, not other buttons |
| `scroll` | A visitor reaches 90% of the page | No |

For a Start trial button that opens a page on your own site, none of these fires, so you need a custom event. If scroll is the signal you care about, [scroll depth tracking](/blog/scroll-depth-tracking) covers going beyond the single 90% event.

## Method 1: send the event from your code with gtag

If the Google tag is already on your page, call `gtag` when the button is clicked. Google's [events guide](https://developers.google.com/analytics/devguides/collection/ga4/events) uses the same form: the command, an event name and an object of parameters.

```html
<button id="start-trial">Start trial</button>

<script>
  document.getElementById("start-trial").addEventListener("click", function () {
    gtag("event", "start_trial_click", { button_location: "pricing_hero" });
  });
</script>
```

Name events in lowercase with underscores, and keep within GA4's [collection limits](https://support.google.com/analytics/answer/9267744): event names and parameter names up to 40 characters, parameter values up to 100 characters, and up to 25 parameters per event on standard properties.

- **Good for:** sites where a developer ships changes anyway; tracking that should survive redesigns, because it lives next to the button's code.
- **Cost:** every new event needs a code change and a release.

## Method 2: use Google Tag Manager

If GA4 runs through Tag Manager, you can add click tracking without touching the site's code. If you are deciding whether you need Tag Manager at all, read [Google Tag Manager vs Google Analytics](/blog/google-tag-manager-vs-google-analytics) first.

1. **Switch on the click variables.** In **Variables**, select **Configure** and tick the built-in [click variables](https://support.google.com/tagmanager/answer/7182738): Click Element, Click Classes, Click ID, Click URL and Click Text.
2. **Find something that identifies the button.** Open **Preview**, click the button on your site, select the click event in the debug panel and look at the **Variables** tab. An id such as `start-trial` is best; a stable class or the button text will do.
3. **Create the trigger.** In **Triggers**, add a [click trigger](https://support.google.com/tagmanager/answer/7679320) of type **All Elements**, choose **Some Clicks**, and set the condition, for example Click ID equals `start-trial`. Use **Just Links** instead if the button is an `<a>` element and you want the Wait for Tags option.
4. **Create the tag.** In **Tags**, add a Google Analytics event tag. Enter your measurement ID, the event name `start_trial_click`, and a parameter `button_location` with the value `pricing_hero` or a variable. Attach the trigger.
5. **Test it.** In Preview, click the button and confirm the tag fired once. Then check GA4's realtime report or DebugView for the event.
6. **Publish** the container version with a short description of the change.

### The child element problem

With **All Elements**, Click Element is the innermost thing clicked. If the button contains an icon or a `<span>`, a click on the icon has no id, and a trigger on Click ID misses it. Use the condition **Click Element matches CSS selector** with a selector that covers the button and everything inside it:

```txt
#start-trial, #start-trial *
```

> **Triggers break silently.** A Tag Manager trigger depends on an id, class or text that a designer can change without knowing the trigger exists. After a redesign, check that your click events still arrive.

## Then: make the click visible in reports

The event is collected from the first click, but a few steps decide whether anyone can use it.

1. **Register parameters as custom dimensions.** In **Admin**, open **Custom definitions** and create an event-scoped dimension for `button_location`. Google notes it takes [24 to 48 hours](https://support.google.com/analytics/answer/14240153) before you can report on a new custom dimension.
2. **Mark it as a [key event](/glossary/key-event) if it is a goal.** If the click is a conversion you care about, mark the event as a key event so it appears in conversion and attribution reports.
3. **Find it.** Open **Reports**, **Engagement**, **Events** and select `start_trial_click`, or build an exploration with the event name and your new dimension.

## A worked example: click-through rate for a button

Counting clicks is only half the answer. Divide them by the views of the page the button is on:

| Page | Pageviews | start_trial_click events | Click rate |
| --- | --- | --- | --- |
| Pricing | 4,000 | 280 | 7.0% |
| Home | 12,000 | 360 | 3.0% |
| Features | 3,000 | 45 | 1.5% |

The home page sends the most clicks, but the pricing page converts attention into clicks more than twice as well. If you count [unique visitors](/blog/how-to-find-unique-visitors-in-ga4) who clicked instead of events, repeat clicks stop inflating the rate. The [conversion rate calculator](/tools/conversion-rate-calculator) does the same sum for any goal.

## Which method should you use?

|  | gtag in code | Tag Manager | HTML attribute |
| --- | --- | --- | --- |
| Needs a code release | Yes | No, after Tag Manager is installed | Yes, but only markup |
| Survives a redesign | Yes, if the code moves with the button | Only if the id or class stays | Yes, the attribute moves with the button |
| Who can add it | Developers | Anyone with container access | Anyone who edits the page template |
| Number of steps | One | Variables, trigger, tag, preview, publish | One |
| Typed values (numbers, booleans) | Yes | Yes | Strings only |

## How to track button clicks in CrispStats

CrispStats takes the third route. Add a `data-cs-event` attribute to the element, and every click on it, or on anything inside it, is sent as a [custom event](/glossary/custom-event) with that name. Each `data-cs-prop-*` attribute on the same element becomes a property:

```html
<button data-cs-event="start trial" data-cs-prop-location="pricing hero">
  Start trial
</button>
```

There is no trigger and no tag to set up, and the child element problem does not arise: the script looks for the closest element with the attribute, starting from what was clicked. It listens in the capture phase, so the click still counts when a handler stops propagation, and it sends with `sendBeacon`, so a link that leaves the page still reports. Elements rendered later by a framework work without extra setup.

Attribute values are always strings, and only clicks count (a key press that activates a button fires a click and is included). For numbers, booleans or events that are not clicks, call `crispstats("start trial", { plan: "growth" })` from your code. Events appear under **Events** in the dashboard within seconds, with no custom dimension to register, and you can use them as steps in [funnels](/features/funnels) or as goals; [conversion funnel analysis](/blog/conversion-funnel-analysis) shows how to read a click as one step of many. The full rules are in the [declarative events docs](https://docs.crispstats.com/track/declarative-events), and the attribute works the same if you load the script [through Tag Manager](/integrations/google-tag-manager).

## How do you track button clicks without cookies?

Add a `data-cs-event` attribute to the button and load the script below. Each click is sent as one event, without a cookie and without an identifier stored in localStorage.

```html
<script defer src="https://in.crispstats.com/d.js" data-site="YOUR_SITE_KEY"></script>
```

```html
<button data-cs-event="book demo" data-cs-prop-location="pricing">
  Book a demo
</button>
```

The attribute value is the event name. Each `data-cs-prop-*` attribute on the same element is sent as a property. A click on an icon or a span inside the button still counts, because the script starts from what was clicked and walks up to the closest element with `data-cs-event`. From code, `crispstats("book demo", { location: "pricing" })` sends the same event when you need a number or a boolean.

### Worked example

The pricing page is viewed 2,000 times and the button sends 160 events named book demo. That is one event per click: 160 clicks, 160 events. Nothing about those clicks is written into a cookie or into localStorage.

The mistake is to invent a second attribute, or to keep a click id in localStorage so you can dedupe later. Use `data-cs-event` for the name and `data-cs-prop-*` for details. It is also a mistake to expect GA4 enhanced measurement to record this button: that covers outbound links, file downloads and form submits, not a button that stays on your site.

## How is a button click rate calculated?

Divide clicks on the button by views of the page it sits on, then multiply by 100. Use people who clicked, instead of events, when one person can click more than once.

```
click rate = clicks ÷ pageviews of that page × 100
visitor click rate = people who clicked ÷ pageviews × 100
```

### Worked example

A features page has 1,500 views and 90 click events on Book a demo. The click rate is 90 ÷ 1,500 × 100 = 6%. Twenty of those events are second clicks, so 70 people clicked: 70 ÷ 1,500 × 100 = 4.7%. If you divide the same 90 clicks by 20,000 site-wide pageviews, you get 0.45%, which describes the site, not the button. The [click-through rate](/glossary/click-through-rate) entry is the same division for ads, and the [conversion rate calculator](/tools/conversion-rate-calculator) runs it for any goal.

The mistake is to mix the two denominators between reports, or to treat 6% and 4.7% as the same kind of rate. Say whether you counted events or people, and keep the denominator as views of the page the button is on.

## Frequently asked questions

### Does Google Analytics 4 track button clicks automatically?

No. Enhanced measurement records outbound link clicks, file downloads, form starts and form submits, but not clicks on buttons that stay on your site. Those need a custom event sent with gtag or from Tag Manager.

### How do I track button clicks in GA4 without Google Tag Manager?

Add a click listener to the button in your code and call gtag with the event command, an event name such as start_trial_click and any parameters. The event appears in realtime and DebugView, and in standard reports after processing.

### Why is my GA4 click event not showing in reports?

Standard reports show events after processing, not instantly, and parameters only become reportable once you register them as custom dimensions, which Google says takes 24 to 48 hours. Check realtime or DebugView first to confirm the event is being sent at all.

### Why does my Tag Manager click trigger only fire sometimes?

Usually because the visitor clicked an icon or text inside the button, so the clicked element has no matching id or class. Use a CSS selector condition that matches the button and its children, for example the button's id followed by the same id with a space and an asterisk.

### Should I track clicks as events or as key events?

Track every click you want to analyse as an event. Mark only the few that represent a real goal, such as starting a trial or requesting a demo, as key events, so conversion and attribution reports stay meaningful.

### How do I track button clicks without cookies?

Add a data-cs-event attribute to the button, with the event name as the value, and load the analytics script. Each click sends one event. The script does not set a cookie and does not store an identifier in localStorage. Attributes whose names start with data-cs-prop- are sent as properties of that event.

### How is a button click rate calculated?

Divide clicks on the button by views of the page it is on, then multiply by 100. 90 clicks on a page with 1,500 views is 6%. If some people click twice, divide the number of people who clicked by those pageviews when you want the share of visitors. Do not divide by every pageview on the site.
