How do I count clicks on a button?

Add a named event goal for the button, then call postdeploy.track with that name in the button's click handler. PostDeploy does not record clicks on its own. An event carries only its name and an optional revenue value, so give each button you want to compare its own goal, and count finished signups separately from clicks.

Last updated 26 November 2026. By Paul Badarau.

A fictional scheduling app has two Start buttons on its landing page, one at the top and one at the bottom. The founder wants to know whether anyone scrolls down far enough to use the second one. They add two named event goals, start_top and start_bottom, and after two weeks the report shows 140 clicks on the top button and 35 on the bottom one.

To count a button:

  1. Ask an Owner or Administrator to add a named event goal, such as start_top. The name in your code must match it exactly. You can change its label later, but not its name.
  2. Mark each button with the goal it completes: <button data-goal="start_top">Start</button>.
  3. Add one script for the whole site, and run it after the page loads. The tracking snippet uses defer, so it is ready by then: document.addEventListener('DOMContentLoaded', function () { document.querySelectorAll('[data-goal]').forEach(function (el) { el.addEventListener('click', function () { window.postdeploy?.track(el.dataset.goal); }); }); });
  4. Click the button yourself and check that the goal appears in the report.

The ?. skips the call when the PostDeploy script is blocked or has not loaded yet, so a click never throws an error. When a click opens another page, the script hands the event to the browser's beacon where it can, which is built to deliver requests while a page unloads.

An event carries only its name and an optional revenue value. It cannot say which of five buttons was pressed unless each has its own goal. If the same button appears on many pages, one goal is enough, because conversions break down by page. A Project holds at most 40 goals, archived ones included, so name the buttons you would act on and skip the rest.

Decide whether the click is the result you want:

  • Count the click when the click is the outcome, such as copying an email address or opening a chat.
  • Count the outcome instead when the button only starts something. A click on a submit button fires even when the form fails validation, so it counts attempts, not signups.

Busy buttons run into limits. Completion counts include repeats, and a visit keeps at most 20 goal events. Each visitor also gets a burst of 20 requests, then about one per second, shared with pageviews and activity signals. A button people press over and over, such as Load more, soon reaches the 20-event cap, so leave it untracked. A visit with a goal is also no longer a bounce, so your bounce rate falls once a new click goal goes live.

The product page for this is Analytics.

Start your 14-day free trial