Event tracking through CSS selectors in Google Tag Manager

This article is in conjunction with the article Introduction to DOM, Nodes & CSS Selectors for Google Tag Manager where I introduced the concept of DOM and CSS selectors. Make sure you read it, in order to get the best out of the present article.

Today I am going to show you, how to use CSS selectors for tracking events in Google Tag Manager.

Tracking clicks on a button via CSS selector in Google Tag Manager

Here is how the whole process would look like:

  1. Find the CSS selector of the button you want to track.
  2. Create a new tag of type Universal Analytics that sends event data to GA on button click.
  3. Test the tag and then publish the container.

Let us suppose you want to track clicks on the ‘Start Assessment’ button on the page: https://www.optimizesmart.com/web-analytics-training-course-promo/

Get the FREE E-Book (62 Pages)

Follow the steps below:

Step-1: Install the chrome extension called ‘SelectorGadget‘ for finding the CSS selector of a page element.

Step-2: Navigate to the page: https://www.optimizesmart.com/web-analytics-training-course-promo/

Step-3: Click on the ‘SelectorGadget’ icon (at the top right-hand side of the browser window) in order to turn on the extension:

Step-4: Now select the ‘Start Assessment’ button and note down the corresponding CSS Selector, displayed in the ‘selectorGadget’ tool:

In my case the CSS selector is: .wpProQuiz_button

Get the FREE E-Book (62 Pages)

Step-5: Turn off the ‘SelectorGadget’ extension by clicking on its icon again (at the top right-hand side of the browser window).

Step-6: Navigate to your GTM account and create a new tag of type ‘Universal Analytics’. Name it something like ‘Send click on the Start Assessment Button’:

Step-7: Create the tag with the following configuration:

Step-6: Create a new trigger with the following configuration:

Step-7: Save the tag and then preview the container.

Step-8: Navigate to the page: https://www.optimizesmart.com/web-analytics-training-course-promo/

Step-9: Click on the ‘Start Assessment’ button and then scroll down the page, where you can see the ‘GTM Debug Console window‘.

Step-10: Click on the ‘gtm.click’ event under ‘Summary’ column in the GTM debug console window:

If you see your tag (in my case the tag is ‘Send click on the Start Assessment Button’) being displayed under the ‘Tags fired on this event’ section, then it means that your tag fires on button click.

Step-11: Click on the tag to see what values are being passed:

Step-12: Scroll down to the ‘Firing Triggers‘ section to check the various filters for your trigger:

You should see a green checkmark next to each filter.

If your tag is not firing then you would see red cross mark next to one or all of your filters.

Thus ‘Firing triggers’ section is a good way to determine, why a tag is not firing.

Step-13: Navigate back to your GTM account and then click on the ‘Leave Preview Mode’ link.

Step-14: Publish the container.

Step-15: Navigate to your Google Analytics reporting view and then click on the ‘Top Events‘ link (under ‘Behavior‘ > ‘Events’) to see the data for the tracked events:

That’s how you can use CSS selectors to track events in Google Tag Manager.

Related Articles

Event Tracking in Google Tag Manager

Event Tracking in Google Analytics

Register for the FREE TRAINING...

"How to use Digital Analytics to generate floods of new Sales and Customers without spending years figuring everything out on your own."

Here’s what we’re going to cover in this training…

#1 Why digital analytics is the key to online business success.

​#2 The number 1 reason why most marketers are not able to scale their advertising and maximize sales.

#3 Why Google and Facebook ads don’t work for most businesses & how to make them work.

#4 ​Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.

#5 The number 1 reason why conversion optimization is not working for your business.

#6 How to advertise on any marketing platform for FREE with an unlimited budget.

​#7 How to learn and master digital analytics and conversion optimization in record time.


My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

Himanshu Sharma

Digital Marketing Consultant and Founder of Optimizesmart.com

Himanshu helps business owners and marketing professionals in generating more sales and ROI by fixing their website tracking issues, helping them understand their true customers' purchase journey and helping them determine the most effective marketing channels for investment.

He has over 12 years of experience in digital analytics and digital marketing.

He was nominated for the Digital Analytics Association's Awards for Excellence. The Digital Analytics Association is a world-renowned not-for-profit association that helps organisations overcome the challenges of data acquisition and application.

He is the author of four best-selling books on analytics and conversion optimization:

error: Alert: Content is protected !!