Event tracking through CSS selectors in Google Tag Manager

This article is 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 which send 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/

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 following configuration:

Step-6: Create a new trigger with 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 green check mark 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

Do you want to Learn and Master Web Analytics in 8 Weeks?

I get dozens of emails every week from people asking for career advice in web analytics.

The questions range from ‘where do I start?’, ‘which books should I read?’, ‘how do I prepare for GAIQ?’ to how do I become a good analyst?

So I thought why not dedicate a whole video on answering these burning questions.

Here is what we are going to cover, in the next few minutes, in this video lesson:

#1 Who am I? What’s my story and why you should listen to me?

#2 The number 1 reason, why most marketers and business owners are not able to scale their advertising and maximize sales for themselves and/or for their clients.

#3 How in just couple of years, I went from a complete novice in web analytics to the author of three best selling books on web analytics? And how you can achieve the same transformation in your career and that too in much shorter time frame.

#4 What is the difference between web analytics and Google Analytics?

Join the Course

Take your analytics knowledge to the next level. Check out my best selling books on Amazon

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

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.

Himanshu Sharma

Certified web analyst and founder of OptimizeSmart.com

My name is Himanshu Sharma and I help businesses find and fix their Google Analytics and conversion issues. If you have any questions or comments please contact me.

  • Over twelve years' experience in SEO, PPC and web analytics
  • Google Analytics certified
  • Google AdWords certified
  • Nominated for Digital Analytics Association Award for Excellence
  • Bachelors degree in Internet Science
  • Founder of OptimizeSmart.com and EventEducation.com

I am also the author of four books:

error: Alert: Content is protected !!