Skip to content

Main Navigation

Keys & Kites Knowledge Base
  • Search
  • SEO
  • Email

SEO

1
  • Track Clicks with Google Tag Manager (GTM) + GA4 — Step‑by‑Step Guide

Email

3
  • Starter Email Frame
  • Central Dispatch Email Template A
  • SFMC Data Extensions Locations

Tutorial

1
  • How to Update Your Email Signature (2025 Guide)
View Categories
  • Home
  • Docs
  • SEO
  • Track Clicks with Google Tag Manager (GTM) + GA4 — Step‑by‑Step Guide

Track Clicks with Google Tag Manager (GTM) + GA4 — Step‑by‑Step Guide

michael.kaminski
Updated on November 18, 2025

4 min read

  • Home
  • Docs
  • SEO
  • Track Clicks with Google Tag Manager (GTM) + GA4 — Step‑by‑Step Guide

What you’ll need #

  • GTM container correctly installed on your site (the <head> + <body> snippets).
  • GA4 property with either a GA4 Configuration Tag in GTM or a Measurement ID ready.
  • Access to Tag Assistant (Preview) and GA4 DebugView.

Tip: If you already send page_view via a GA4 Configuration tag in GTM, you’re set. If not, create that first and fire it on All Pages.

Step 1 — Identify the button selector #

Decide how you’ll target the button: by an id (preferred when unique) or by a class.

Example: By id #

<button id="signup-btn" class="btn btn-primary">Start Free Trial</button>

Selector to use: #signup-btn

Example: By class #

<button class="cta download-btn">Download Now</button>

Selector to use: .download-btn (or .cta.download-btn for extra specificity)

Heads‑up: If multiple buttons share the same class, you’ll track all of them. If you only want one, prefer a unique id or use a more specific CSS selector.

Step 2 — Enable GTM click variables #

  1. Open Google Tag Manager → Variables.
  2. Under Built‑In Variables, click Configure and enable:
    • Click ID
    • Click Classes
    • Click Text
    • Click URL (handy for links)

Step 3 — Create a Click trigger targeting your button #

  1. Go to Triggers → New.
  2. Choose Trigger Type: Click – All Elements (works for buttons, not just links).
  3. Select Some Clicks and add a condition using your selector:
    WhenOperatorValueNotes
    Click ID equals signup-btn Best when the button has a unique id.
    Click Classes contains download-btn Good when targeting by class.
    Click Element matches CSS selector #signup-btn or .cta.download-btn Most flexible (supports full CSS selectors).
  4. Name it clearly, e.g., TRG — Click — #signup-btn.

Pro move: The matches CSS selector operator is incredibly reliable across varied markup. Prefer it when in doubt.

Step 4 — Create a GA4 Event tag #

  1. Go to Tags → New.
  2. Choose Tag Type: Google Analytics: GA4 Event.
  3. Set Configuration Tag to your existing GA4 Configuration tag (or add your GA4 Measurement ID if you use the newer GA4 Event + Measurement ID pattern).
  4. Set Event Name to something future‑proof, e.g. button_click or cta_click.
  5. Add event parameters (recommended):
    button_id: {{Click ID}}
    button_classes: {{Click Classes}}
    button_text: {{Click Text}}
    click_url: {{Click URL}}
  6. Under Triggering, select the trigger you created in Step 3.
  7. Name it e.g., TAG — GA4 Event — button_click — #signup-btn and save.

Step 5 — Preview & debug in Tag Assistant #

  1. Click Preview in GTM and enter your site URL.
  2. In the connected browser window, click the target button.
  3. Back in Tag Assistant, find the related Click event in the left panel and confirm your tag fired.
  4. Verify variables in the Variables tab (e.g., Click ID, Click Classes, Click Text).

If it didn’t fire: Confirm you used the correct selector, the click actually occurs on the button element (not a child), and that no front‑end framework prevents default clicks. Try the matches CSS selector operator against Click Element.

Step 6 — Confirm receipt in GA4 DebugView #

  1. Open GA4 → Admin → DebugView (or use Reports → Realtime).
  2. Perform the click while Tag Assistant is connected.
  3. Look for your button_click event and expand it to see parameters.

Step 7 — Publish #

  1. In GTM, click Submit.
  2. Add a descriptive Version Name and Notes (e.g., “Add button_click for #signup-btn”).
  3. Publish.

Optional — Make the data easy to report in GA4 #

If you want to use parameters (e.g., button_text or button_id) in standard reports, register them as custom dimensions:

  1. GA4 → Admin → Custom definitions → Create custom dimension.
  2. Scope: Event. Event parameter: choose button_text (or the parameter you added).
  3. Save. Data populates moving forward.

Explorations: For ad‑hoc analysis, use Explore → create a Free Form; add Event name as a filter = button_click, then use button_text or button_id as a dimension.

Step 8 — View & report your button clicks in GA4 #

Quick QA (now) #

  1. Realtime: GA4 → Reports → Realtime. Click your page in the map/list, then look under Event count by Event name for button_click.
  2. DebugView: GA4 → Admin → DebugView. Click your most recent event and expand to see button_id, button_text, etc.

Standard reports (counts over time) #

  1. Go to Reports → Engagement → Events.
  2. Find button_click in the table and click it to open the event detail view.
    • Event count shows total clicks.
    • To break down by button_id or button_text, first register them (see the “Optional — Make the data easy to report” section above), then use the report’s Customize (pencil icon) to Add dimension and include your parameter.

Mark important buttons as conversions (optional) #

  1. GA4 → Admin → Events.
  2. Find button_click and toggle Mark as conversion (or create a rule‑based custom event like signup_cta_click that matches event_name=button_click and button_id=signup-btn, then mark that as a conversion).
  3. See results in Reports → Engagement → Conversions.

Explorations (flexible tables & trends) #

  1. Explore → Free form.
  2. Click + next to Dimensions and add Event name, button_id, button_text.
  3. Add metric Event count.
  4. Drag button_id (or button_text) to Rows, drag Event count to Values.
  5. Add a filter: Event name equals button_click.

Dashboards (Looker Studio) #

  1. Create a Looker Studio report → Connect GA4 property.
  2. Build a table with button_id or button_text as a dimension and Event count as metric. Filter event name to button_click.

Raw data (BigQuery export, optional) #

1
2
3
4
5
6
7
8
9
SELECT
  PARSE_DATE('%Y%m%d', event_date) AS date,
  ep.value.string_value AS button_id,
  COUNT(*) AS clicks
FROM `YOUR_PROJECT.YOUR_DATASET.events_*`, UNNEST(event_params) ep
WHERE event_name = 'button_click'
  AND ep.key = 'button_id'
GROUP BY 1, 2
ORDER BY 1, 2;
Notes
  • Retention: GA4’s event data retention setting (Admin → Data settings) controls how far back you can analyze in Explore. Dashboards and standard reports aren’t affected the same way.
  • Attribution: If you mark a button as a conversion, attribution and traffic source breakdowns appear in standard conversion reports.

Troubleshooting checklist #

  • Nothing fires in Preview: Confirm GTM snippet is present on the page you’re testing (view source or use browser extensions).
  • Wrong button tracked: Tighten your CSS selector; prefer #unique-id or a more specific class chain.
  • Clicks inside nested elements: Try targeting the parent button via Click Element matches CSS selector (e.g., button#signup-btn).
  • SPA or framework issues: Some frameworks intercept clicks. Consider a Custom Event trigger if the app dispatches one, or listen for history change in SPA setups.
  • Missing parameters in GA4 reports: Make sure you registered the parameter as a custom dimension (Admin → Custom definitions) and wait for new data.
Quick recipe (copy me)
1) Variables → Enable: Click ID, Click Classes, Click Text, Click URL
2) Trigger → Click – All Elements → Some Clicks
   Condition: Click Element matches CSS selector  #signup-btn
3) Tag → GA4 Event
   Event name: button_click
   Params: button_id {{Click ID}}, button_text {{Click Text}}, button_classes {{Click Classes}}
4) Attach trigger from (2) to tag from (3)
5) Preview (Tag Assistant) → click button → verify
6) DebugView (GA4) → confirm event + params
7) Submit & Publish
This button is for testing purposes #
Test Click
Element ID: test-click
Maintained: This guide reflects current GTM + GA4 UI concepts (Click variables, “matches CSS selector”, Tag Assistant Preview, GA4 DebugView). If Google updates naming or locations, the workflow still holds: collect click → send event → validate → publish → report.
GA4, Google Tag Manager, GTM
Table of Contents
  • What you’ll need
  • Step 1 — Identify the button selector
    • Example: By id
    • Example: By class
  • Step 2 — Enable GTM click variables
  • Step 3 — Create a Click trigger targeting your button
  • Step 4 — Create a GA4 Event tag
  • Step 5 — Preview & debug in Tag Assistant
  • Step 6 — Confirm receipt in GA4 DebugView
  • Step 7 — Publish
  • Optional — Make the data easy to report in GA4
  • Step 8 — View & report your button clicks in GA4
    • Quick QA (now)
    • Standard reports (counts over time)
    • Mark important buttons as conversions (optional)
    • Explorations (flexible tables & trends)
    • Dashboards (Looker Studio)
    • Raw data (BigQuery export, optional)
  • Troubleshooting checklist
    • This button is for testing purposes
Keys & Kites
  • Docs
Keys & Kites 2025 ©