Tracking button clicks with Google Tag Manager (GTM) involves setting up a tag and a trigger that will fire whenever the button is clicked. Here’s a detailed guide to achieve this:
Table of Contents
Toggle1. Enable Click Variables
-
- Go to Google Tag Manager and log in with your account.
- Select the container you want to work with.
- In the GTM dashboard, click on Variables in the left-hand menu.
- Under Built-in Variables, click on Configure.
- Check the boxes for Click ID, Click Classes, Click Text, and any other variables you might need.
2. Create a Trigger for Button Clicks
- Create a New Trigger:
- Click on Triggers in the left-hand menu.
- Click on New to create a new trigger.
- Click on Trigger Configuration and select Click – All Elements or Click – Just Links based on your button type.
- Configure the Trigger:
- Choose Some Clicks to narrow down to specific buttons.
- Set the conditions for your button click trigger. For example:
- Click Text equals
Subscribe
- Click Classes contains
button-class
- Click ID equals
button-id
- Click Text equals
- Save the Trigger:
- Give your trigger a name (e.g., “Subscribe Button Click”) and click Save.
3. Create a Tag to Track the Event
- Create a New Tag:
- Click on Tags in the left-hand menu.
- Click on New to create a new tag.
- Click on Tag Configuration.
- Select Tag Type:
- Choose Google Analytics: GA4 Event if using GA4, or Universal Analytics if using the older version.
For GA4:
- Select Google Analytics: GA4 Event.
- Enter your Measurement ID.
- In the Event Name field, enter a name for the event (e.g.,
button_click
). - Add parameters if needed (e.g.,
button_text
with value{{Click Text}}
).
For Universal Analytics:
- Select Universal Analytics.
- Set the Track Type to Event.
- Fill in the Category (e.g.,
Button
), Action (e.g.,Click
), and Label (e.g.,Subscribe Button
). - Set your Google Analytics Settings Variable or enter your Tracking ID.
- Add the Trigger:
- Click on Triggering and select the trigger you created in Step 2.
- Save the Tag:
- Give your tag a name (e.g., “GA4 Button Click Event” or “UA Button Click Event”) and click Save.
4. Publish the Container
-
- Click on Submit in the top-right corner of the GTM interface.
- Add a version name and description for the changes you’re publishing.
- Click Publish to make the changes live on your website.
5. Test the Tag
-
- Click on Preview in the top-right corner of GTM.
- This will enable preview mode. Navigate to your website and perform the button click you want to track.
- Use the GTM debug console to verify that the button click triggers the tag correctly.
- Go to your Google Analytics account.
- For GA4: Check the Realtime and Events reports.
- For Universal Analytics: Check the Realtime and Behavior > Events reports.
By following these steps, you can track button clicks on your website using Google Tag Manager and view the data in Google Analytics. This allows you to analyze user interactions and optimize your website accordingly.