{"id":220,"date":"2021-01-21T15:56:31","date_gmt":"2021-01-21T15:56:31","guid":{"rendered":"https:\/\/organicdigital.co\/blog\/?p=220"},"modified":"2026-05-15T07:06:19","modified_gmt":"2026-05-15T06:06:19","slug":"how-to-track-link-or-banner-clicks-in-the-main-content-area-of-a-page-using-gtm","status":"publish","type":"post","link":"https:\/\/daveashworth.co\/blog\/how-to-track-link-or-banner-clicks-in-the-main-content-area-of-a-page-using-gtm\/","title":{"rendered":"How To:  Track Link or Banner Clicks In The Main Content Area Of A Page Using GTM"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">As part of their monthly reporting, and to assist with determining which banners and content on the home page capture a user&#8217;s interest, a client asked me to track which links on their home page were being clicked.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This type of <a href=\"https:\/\/daveashworth.co\/blog\/how-to-configure-events-and-conversions-for-google-analytics-4\/\">engagement tracking<\/a> can provide much deeper insight than page views alone.  Similar approaches can also be used to track <a href=\"https:\/\/daveashworth.co\/blog\/how-to-track-internal-link-clicks-in-google-analytics-4-via-gtm\/\">internal navigation behaviour<\/a> and user journeys throughout a website.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As an establised <a href=\"https:\/\/daveashworth.co\/skills\/google-tag-manager-consultant\/\">Google Tag Manager consultant<\/a> I know that link clicks are very easy to track with GTM, and it\u2019s also straight forward to create a trigger that allows you to track links on a specific page \u2013 the tricky part was figuring out how to do so within a specific &lt;div&gt; or &lt;section&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Most web templates these days are split into 3 sections:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Header \u2013 where the main navigation, logo, search box and useful internal links go<br><\/li>\n\n\n\n<li>Main Content \u2013 this is the main body of the page and where (you should) find unique content<br><\/li>\n\n\n\n<li>Footer \u2013 newsletter sign ups, useful internal links, social media links etc<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Tracking engagement within these areas can help identify which content drives the most <a href=\"https:\/\/daveashworth.co\/blog\/how-to-configure-events-and-conversions-for-google-analytics-4\/\">interaction and conversions<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In some cases, it would also be useful to track popular menu items or to see if users interact with your footer, but in this instance the internal links we are interested in are in the main content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Most website templates tend to use the same elements for various sections of the page, those being:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&lt;header&gt;<\/li>\n\n\n\n<li>&lt;main&gt;<\/li>\n\n\n\n<li>&lt;footer&gt;<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">We are interested in the &lt;main&gt; element, and we will need the css identifier for this \u2013 either the class or ID assigned to &lt;main&gt; \u2013 you can find this easily via the inspect tool \u2013 in the case of my home page, the id is \u201cmaincontent\u201d (as it is with many templates, such as out of the box <a href=\"https:\/\/daveashworth.co\/skills\/ecommerce-seo-consultant\/magento\/\">Magento<\/a> themes).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"681\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/web_page_inspect_tool-1024x681.jpg\" alt=\"Web Page Code Inspect Tool\" class=\"wp-image-221\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/web_page_inspect_tool-1024x681.jpg 1024w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/web_page_inspect_tool-300x199.jpg 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/web_page_inspect_tool-150x100.jpg 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/web_page_inspect_tool-768x510.jpg 768w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/web_page_inspect_tool.jpg 1291w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In GTM, we then create a trigger type \u201cJust Links\u201d which will track \u201csome link clicks\u201d.\u00a0 The event that we need to create is any link click within the element \u201cmaincontent\u201d.\u00a0\u00a0 This bit had me stumped as I assumed it would be \u201c<a href=\"https:\/\/daveashworth.co\/skills\/google-tag-manager-consultant\/\">matches CSS selector<\/a>\u201d and #maincontent, though this didn\u2019t do anything, as it technically would be trying to track any clicks on the maincontent div as opposed to elements within the div.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After much experimenting, I gave up and decided to tweet GTM expert <a href=\"https:\/\/twitter.com\/SimoAhava\" target=\"_blank\" rel=\"noopener\">Simon Ahava<\/a> who was more than happy to point me in the right direction:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"586\" height=\"853\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/twitter_conversation_with_simon_ahava.jpg\" alt=\"Twitter Conversation with Simon Ahava\" class=\"wp-image-222\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/twitter_conversation_with_simon_ahava.jpg 586w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/twitter_conversation_with_simon_ahava-206x300.jpg 206w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/twitter_conversation_with_simon_ahava-103x150.jpg 103w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As he explains in his <a href=\"https:\/\/www.simoahava.com\/analytics\/use-wildcard-css-selectors-with-all-elements-triggers\/\" target=\"_blank\" rel=\"noopener\">Wilcard CSS Selectors article<\/a>.   Techniques like this are particularly useful when implementing more advanced <a href=\"https:\/\/daveashworth.co\/skills\/analytics-and-ad-tracking-consultant\/google-analytics-4\/\">GA4 interaction tracking setups.<\/a><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>The wildcard selector literally means any descendant of the preceding selector. So given a selector like div#nav * would match any elements that are nested with a &lt;div id=&#8221;nav&#8221;&gt; element, but not the &lt;div&gt; element itself.<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">So in my case, the \u201cmatches CSS selector\u201d command is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#maincontent, #maincontent *<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Further to this, to ensure this only fires on the home page add the condition &#8220;Page Path&#8221; &#8220;equals&#8221; \/<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"737\" height=\"645\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/2021-01-21_15-49-06.jpg\" alt=\"GTM Trigger To Track Home Page Links\" class=\"wp-image-224\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/2021-01-21_15-49-06.jpg 737w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/2021-01-21_15-49-06-300x263.jpg 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/2021-01-21_15-49-06-150x131.jpg 150w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once the trigger has been created, you can then create an event which will track the URL of the internal link that has been clicked as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"726\" height=\"648\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/2021-01-21_15-35-35.jpg\" alt=\"GTM Tag To Track Link Click As An Event\n\" class=\"wp-image-225\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/2021-01-21_15-35-35.jpg 726w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/2021-01-21_15-35-35-300x268.jpg 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/2021-01-21_15-35-35-150x134.jpg 150w\" sizes=\"(max-width: 726px) 100vw, 726px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Similar methods can also be used to track <a href=\"https:\/\/daveashworth.co\/blog\/how-to-get-track-form-field-submission-values-in-analytics-using-gtm\/\">form interactions<\/a> and other <a href=\"https:\/\/daveashworth.co\/blog\/how-to-configure-events-and-conversions-for-google-analytics-4\/\">custom engagement events<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can then see, via real time tracking or event tracking, which home page links are receiving clicks \u2013 in my case, it will be interesting to see which sections of the home page are of interest to visitors, and if they scroll down and click through to my key services:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"704\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/seo_services-1024x704.png\" alt=\"Key Services on Home Page\" class=\"wp-image-243\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/seo_services-1024x704.png 1024w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/seo_services-300x206.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/seo_services-150x103.png 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/seo_services-768x528.png 768w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/seo_services.png 1067w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In <a href=\"https:\/\/daveashworth.co\/skills\/analytics-and-ad-tracking-consultant\/google-analytics-4\/\">Google Analytics<\/a> real time event tracking we see:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1012\" height=\"229\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/real_time_tracking.jpg\" alt=\"GA Real Time Tracking\" class=\"wp-image-228\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/real_time_tracking.jpg 1012w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/real_time_tracking-300x68.jpg 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/real_time_tracking-150x34.jpg 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2021\/01\/real_time_tracking-768x174.jpg 768w\" sizes=\"(max-width: 1012px) 100vw, 1012px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Real-time reporting is also useful when <a href=\"https:\/\/daveashworth.co\/blog\/solved-why-google-tag-manager-events-are-not-showing-in-analytics\/\">debugging events that aren\u2019t appearing correctly in GA4<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fair to say, this is very useful data to have \u2013 if this is the sort of data you need in your analytics and reporting and need any help getting it set up, feel free to get in touch.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you need help implementing advanced GTM event tracking or improving user engagement reporting, take a look at my <a href=\"https:\/\/daveashworth.co\/skills\/analytics-and-ad-tracking-consultant\/\">analytics and tracking consultancy services<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Find out the most popular links and\/or banners on your home page with this easy to implement event tracking.<\/p>\n","protected":false},"author":1,"featured_media":230,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,8],"tags":[],"class_list":["post-220","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","category-tag-manager"],"_links":{"self":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts\/220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/comments?post=220"}],"version-history":[{"count":2,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":2102,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts\/220\/revisions\/2102"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/media\/230"}],"wp:attachment":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/categories?post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/tags?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}