How to track Google Analytics events via Google Tag Manager
You can track Google Analytics events via Google Tag Manager by creating a Google Analytics tag of type ‘Event’ and then creating a specific trigger to track specific time of users’ interactions (like PDF Downloads, image link clicks, button clicks, form submissions, form fields, video watching, scrolling, external link clicks etc.).
Every time you want to track a new page element, you need to create a new Google Analytics tag of type ‘Event’. This tag is used to send event tracking data (Event Category, Event Action, Event Label and Event Value) to Google Analytics.
Basics of event tracking
Step-1: Compile a list of events that you would like to track.
Step-2: Create event triggers for each event you would like to track on the page using CSS element selectors.
Step-3: Set up tags for each event and link to the triggers accordingly.
Step-4: Validate the tags created using GTM preview mode.
Step-5: Check if the event data is flowing in the Google Analytics real-time reports.
Step-7: Once the validation is completed, you can publish the changes in the GTM.
These are the basic steps that need to be followed for every type of event (link tracking, button tracking, etc.) using Google Tag Manager.
Firing Triggers: Check for clicks on the download button
Here,
{{Page Path}} is the page path variable.
The Page Path variable returns the Request URI of a web page.
For example,
For the URL: https://www.optimizesmart.com/contact/
The Request URI is: /contact/
I have used ‘Page Path’ as the event label so that in my event tracking reports, I can see the page on which the button was clicked. This can be useful if you have embedded the same button on multiple pages of your website.
Non-Interaction Hit – Set non-interaction Hit to ‘True’ so that event tracking does not affect the bounce rate of your website.
Step-8: Navigate to the web page (in Google Chrome browser), which contains the button you want to track via GTM. You should now see the Google Tag Manager Debug console window as shown below:
Step-9: Enter the URL you need to debug and click on the ‘Start’ button.
Step-10: You will see the preview mode enabled on the page.
Step-11: Additionally, on the website, where the preview mode is enabled, you would see an alert like below, which states that debug mode is enabled on the page.
Step-12: Click on the button on the website and then click on the ‘Debug’ tab. You will notice that the button click event to GA is triggered.
If you see the tag ‘Send button clicks to GA as event‘ listed under the ‘Tags Fired’ section,it means that your tag fires on button click.
Step-13: You can even click on the event triggered to check if the event parameters (event category, action and label) are fired on the page as expected.
Step-14: To double-check that your tag is firing and sending events data to Google Analytics, navigate to Real Time >> Events report in your main Google Analytics reporting view:
Step-15: Navigate back to your GTM account and click on ‘Submit’.
Step-16:After you click to submit changes, you will see a window, like below, where you can create a version and publish the version.
Step-17: Create a version. Make sure to give a proper version name so that it would be easy to track what changes went live in that version. Ex: Send button events in GA.
Step-18: After updating the version name and description, click on the ‘Publish’ button on the right-hand side.
Tracking clicks on a button that is embedded across a website
The whole process of tracking clicks on the button, which is embedded across a website instead of just one particular page, is similar to tracking clicks on a button embedded on a single page.
The only difference is that you set the ‘Page URL’ to .* so that trigger can fire on any page of your website when you create the trigger.
How to track link clicks in Google Tag Manager (tracking PDF downloads)
Consider the following link on a web page:
<a id="checklist" href="http://www.optimizesmart.com/Worksheets/seo-guide.pdf" >Download SEO Guide</a>
To track clicks on this link, follow the steps below:
Step-1: Navigate to the web page (in Google Chrome browser), which contains the link you want to track via GTM.
Step-2: Note down the web page URL where the link is embedded. Let us suppose that the URL is: https://www.optimizesmart.com/62952-2/
Step-3: Right-click on the link and select ‘Inspect‘ from the drop-down menu:
You will now see the Google developer console window at the bottom of the page:
Step-4: Note down the value of the ‘id’ attribute of the anchor tag (<a>). In our case, it is ‘checklist’.
You will need this ‘id’ later on while setting up triggers in GTM.
In HTML, the ‘id’ attribute uniquely identifies an HTML element (like link, button, etc).
The ‘id’ attribute’s value must be unique and must not contain any white space.
For example,
<a id=”checklist” href=”…
Here <a> is an HTML element
and ‘id’ is the attribute of <a> element which is used to uniquely identify this element in a HTML document.
Note: If you do not find any ‘id’ attribute for the link you want to track, look for the unique class name. If you can’t find a unique class name, ask your developer to add the ‘ID’ attribute with a unique value. Without the ID attribute, you can’t easily track clicks on a link via GTM.
Step-5: Navigate to Google Tag Manager and create a new trigger with the following similar configurations:
Trigger Name: Check for clicks on the download link
Trigger Type: Click – Just links
Check Validation
Enable this trigger when:
Page URL equals <<enter the URL of the page where the link you want to track is embedded>>
This trigger fires on:
Some Link Clicks
Click ID equals <<enter the ID of your <a> element>>
Note: ‘Check Validation‘ ensures that the trigger fires on a successful link click and not just when a user tries to click the link.
Step-6: Create a new tag with the following similar configuration, which can send clicks on the tracked link to Google Analytics as an event:
Tag Name: Send clicks on the download link to GA as event
Tag Type: Google Analytics: Universal Analytics
Track Type: Event
Category: Link Clicks
Action: <<enter the name of your event action>>
Label: {{Page Path}}
Value: <<enter your event value. This is optional>>
Non-Interaction Hit: True
Google Analytics Settings:<<Select your Google Analytics Settings Variable>>
Firing Triggers: Check for clicks on the download link
Step-7: Preview your container.
Step-8: Navigate to the web page (in Google Chrome browser), which contains the link you want to track via GTM and then click on the link.
Step-9: To check that your tag is firing and sending events data to Google Analytics, navigate to Real-Time >> Events report in your main Google Analytics reporting view:
Step-10: Navigate back to your GTM account and then publish the container.
How to track outbound link clicks via Google Tag Manager
Outbound links (also known as external links) are links to other websites from your website.
Tracking clicks on all outbound links is known as exit tracking or outbound tracking.
You can measure the volume of traffic your website is sending out to other websites through exit tracking. This type of tracking is especially useful if you run an affiliate website.
Follow the steps below to track clicks on all outbound links on your website via Google Tag Manager:
Step-1: Create a new trigger with the following similar configuration:
Trigger Name: Check for clicks on External links
Trigger Type: Click – Just Links
Check Validation
Enable this trigger when all of these conditions are true:
Fire this trigger when an event occurs, and all of these conditions are true:
Click URL does not contain <<yourdomain.com>>
Note(1): replace ‘yourdomain.com’ with your website name.
Note(2): ‘Click URL’ is a built-in variable in GTM, which returns the ‘URL’ of the clicked link.
Note(3): The ‘Fire this trigger’ condition makes sure that this trigger does not fire for clicks on the links which are internal, i.e. the links that contain your domain name.
Step-2: Create a new tag with the following configuration, which sends clicks on external links to Google Analytics:
Tag Name: Send Clicks on external links to Google Analytics
Tag Type: Google Analytics: Universal Analytics
Track Type: Event
Category: Traffic to Other Websites
Action: {{Click URL}}
Label: {{Page Path}}
Value:<<leave this field empty>>
Non-Interaction Hit: True
Google Analytics Settings:<<Select your Google Analytics Settings Variable>>
Firing Triggers: Check for clicks on External links
Note(1): {{Click URL}} is a built-in variable in GTM which returns the URL of the link clicked. You can select this variable from the drop-down menu.
Note(2): {{Page Path}} is a built-in variable in GTM which returns the URL of a web page.
Step-3: Preview your container.
Step-4: To check that your tag is firing and sending events data to Google Analytics, navigate to Real-Time >> Events report in your main Google Analytics reporting view:
Step-5: If everything is working as intended, then publish the new version of your container.
How to track link clicks on images in Google Tag Manager
Consider the following image link (link in the form of an image):
To track clicks on an image link, follow the steps below:
Step-1: Navigate to the web page (in Google Chrome browser) which contains the image link you want to track via GTM
Step-2: Note down the web page URL where the image link is embedded.
Step-3: Note down the ‘ID’ attribute of the image link through the Google developer console (as explained earlier). If the ‘ID’ attribute is missing, ask your developer to add one.
Step-4: Navigate to Google Tag Manager and create a new trigger with the following similar configurations:
Trigger Name: Check for link clicks on image
Trigger Type: Click – Just links
Check Validation
Enable this trigger when:
Page URL equals <<enter the URL of the page where the image link you want to track is embedded>>
Some Link Clicks
This trigger fires on:
Click ID equals <<enter the ID of your <a> element>>
Note: If you want to use the ‘id’ attribute of the image tag instead of the ‘id’ attribute of the <a> tag to identify your image link:
Value:<<enter your event value. This is optional>>
Non-Interaction Hit: True
Google Analytics Settings:<<Select your Google Analytics Settings Variable>>
Firing Triggers: Check for link clicks on image
Step-6: Preview your container.
Step-7: Click on the image link and test whether the event data is being sent to Google Analytics via Real Time > Events reports in your main Google Analytics reporting view:
To track form submissions on a website via Google Tag Manager, follow the steps below:
Step-1: Note down the page URL where your form is embedded. For example:
Step-2: Find the form ID (through Google Developer Console) and make a note of it. To find your form ID, right-click on the form, select ‘Inspect Element’ (Google Chrome) and look for the ‘ID’ attribute in the <form> tag. In my case, the form ID is ‘gform_1’:
Step-3: Create a new trigger to check for form submissions with the following similar configurations:
Trigger Name: Check for form submit
Trigger Type: Form Submission
Check Validation
Enable this trigger when all of these conditions are true:
Page URL equals <<enter the URL of the page where your form is embedded>>
This trigger fires on: Some Forms
Fire this trigger when an event occurs, and all of these conditions are true:
Form ID equals <<enter the ID of your embedded form>>
Note(1): If your form is embedded on several pages across your website, set the ‘Page URL‘ to .* as explained earlier.
Note(2): Ensure that the ‘check validation‘ option is checked. This is done to ensure that the trigger fires on successful form submission and not just when a user clicks on the form submit button.
Note(3): ‘Form ID’ is a built-in variable of GTM which returns the ‘id’ attribute of a form.
Step-4: Create a new tag of type Universal Analytics to send the form submit event to Google Analytics:
Tag Name: Send form submit event to Google Analytics
Tag Type: Google Analytics: Universal Analytics
Track Type: Event
Category: New Lead
Action: {{Page Path}}
Value: <<enter your event value. This is optional>>
Non-Interaction Hit: True
Google Analytics Settings: <<Select your Google Analytics Settings Variable>>
Firing Triggers: Check for form submit.
Note: I have used ‘Page Path’ as event action so that in my event tracking reports, I can see the page on which the ‘Form submit’ event was triggered. This is useful if you have embedded the same form on multiple pages of your website.
Step-5: Preview your container.
Step-6: Navigate to the page which contains the form submit button and then click on it.
Step-7: Check whether the event data is sent to Google Analytics via Real Time >> Events reports.
Step-8: If everything is working as intended, then publish the new version of your container.
Sometimes manually tracking something when better alternatives are available is not the best use of your limited time and resources. Tracking form fields via GTM is one of those tasks.
While it is technically possible to track each and every form field value, field abandonment, and various form events, I have found that it is better to leave this type of tracking to the in-page analytics tools (like Hotjar), which provide much better functionality.
Manually tracking form fields is difficult, time-consuming, and prone to errors. The implementation depends on how your form has been set up, which fields it has, and the technology behind it.
But if you still want to reinvent the wheel, here is the detailed guide on tracking form fields. However, remember that the functionality you will get through manual form field tracking is likely to be very basic.
It provides excellent form tracking solutions in addition to heatmaps, session recordings, and funnel analysis. Its form tracking report is much better than you can ever get through Google Tag Manager:
Hotjar provides the following form tracking functionality:
Time spent on each form field (measured in seconds).
% of re-filled for each field.
Number of interactions with each field.
% of drop off at each field step.
Conversion rate of the form.
Visualization of user flow from the first form field to the last.
No matter which in-page analytics tool you use, the important point to remember here is that you don’t have to track everything via GTM just because you are using GTM.
GTM is not the solution to all of your tracking problems, and if a tag does not work via GTM, feel free to hard code it on your website or look for other alternatives. Using GTM won’t make you independent from IT anyway. If nothing else, you still need an IT/developer to hard code data layers on your website.
There is no rule set in stone that once you start using GTM, you are not allowed to hard code tags on your website ever again or look for other alternatives.
Many tags don’t work when deployed via GTM (either because you can’t figure out how to make them work or there are some technical constraints). One good example is the Facebook JavaScript SDK.
I mentioned partial deployment (with and without GTM) because I get a lot of emails from folks who get stuck with their implementation because they feel compelled to use GTM for all of their tracking needs.
It doesn’t need to be that way.
Video tracking via Google Tag Manager
To learn about implementing video tracking via GTM, check out the following two articles:
Please note that to implement custom events in Google Tag Manager, you will need a developer’s help to implement a data layer on the pages that you would like to track.
Let us take an example of implementing custom events on the website.
Say you have a download button to be tracked on the various pages. You can normally implement this using the download event tracking discussed previously. However, if too many download buttons need to be tracked, it would not be easy to use that method. In that case, we can use custom event tracking.
You would need to ask your developer to implement a data layer on all the pages and give a unique key to identify the download buttons on all pages.
Say your developer agreed to pass ‘downloadtracking’ on all download links on the pages.
To set this up as the trigger in your Google Tag Manager, please follow the steps:
Step-1: Click on ‘New’ in the trigger section.
Step-2: From the choose trigger type, select ‘Custom event’ as shown below.
Step-3: In ‘Trigger configuration’, provide the same name that has been passed by the developer in the data layer.
Since, in our case, it is ‘downloadtracking’, we use the same in the trigger condition.
Step-5: Now, this trigger should be associated with the tag to track all the download events on the website.
Other articles on specialized tracking in Google Analytics
Frequently Asked Questions for Google Tag Manager Event Tracking Tutorial
What events can I track?
You can track user interactions such as PDF downloads, image link clicks, button clicks, form submissions, form fields, video watching, scrolling, external link clicks, etc.
Is there anything I need to do before starting event tracking?
You will need to ensure you have enabled all the built-in variables of types: pages, clicks, forms, videos, scrolling, and visibility. This ensures that all these variables will be available to you when you create new tags and triggers later on that are required for event tracking.
How do I set up event tracking in Google Analytics?
Whenever you want to track a new page element, you need to create a new Google Analytics tag of type ‘Event’. This tag is used to send event tracking data to Google Analytics, e.g. Event Category, Event Action, Event Label and Event Value, etc.
Do I have to track every event through Google Tag Manager?
No. Just because you are using Google Tag Manager, you don’t have to track everything via GTM. GTM is not the solution to all of your tracking problems, and if a tag does not work via GTM, feel free to hard code it on your website or look for other alternatives.
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 BeyondSECOND EDITION OUT NOW!
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.
About the Author
Himanshu Sharma
Founder, OptimizeSmart.com
Over 15 years of experience in digital analytics and marketing
Author of four best-selling books on digital analytics and conversion optimization
Nominated for Digital Analytics Association Awards for Excellence
Runs one of the most popular blogs in the world on digital analytics
Consultant to countless small and big businesses over the decade
Get My Step-By-Step Blueprint For Finding The Best KPIs (32 pages ebook)
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.