Tracking button clicks shouldn't require a developer
You want to track when someone clicks "Add to Cart," submits a contact form, or clicks a CTA button. Google Tag Manager can do it, but creating the trigger requires opening GTM, navigating the interface, defining a trigger, creating a tag, setting variables, and publishing the container.
For "track clicks on this button," that's a lot of steps in a separate tool.
What most people do instead
A better way: define the event from the navigator
Open the navigator. Name the event, specify the target element by CSS class or ID, and the command generates a dataLayer push that fires on click. The tracking script is injected on the frontend automatically.
Works with any GA4 + GTM setup. The command pushes to window.dataLayer. If you have GTM installed (via the tracking pixels command or manually), your GA4 tag picks up the events automatically.
How it works
-class, -id, or -form_id to target precisely.dataLayer.| Detail | Value |
|---|---|
| Command name | create gtm event |
| Event name | -name=cta_click (required) |
| Target element | -target=button (required, CSS selector) |
| By CSS class | -class=hero-cta |
| By element ID | -id=signup-btn |
| By form ID | -form_id=contact-form |
| Value selector | -value_selector=.price (captures text content) |
| Can be used in |
Real example
You're running Google Ads to a landing page with a "Get Started" CTA button. The button has the CSS class hero-cta. You need to track clicks as conversions in GA4 so you can measure which ad copy drives the most signups.
You open the navigator and create a GTM event targeting that button class. The dataLayer push fires on every click. In GA4, you mark "cta_click" as a conversion event. Now every ad click that leads to a CTA click is tracked end-to-end.
Next week, you want to track form submissions too. Another event, targeting the form by ID. Two commands, two conversion events, zero code written.