1(function (Drupal) { 2 3 Drupal.behaviors.footerAnalytics = { 4 attach(context) { 5 6 const links = once('footerAnalytics', '.footer-full a', context); 7 8 // Loop through all matched footer links. 9 for (const el of links) { 10 11 // Add a click listener to each link. 12 el.addEventListener('click', function (event) { 13 14 const classes = el.classList; 15 16 // Default values for analytics. 17 let linkText = el.textContent.trim(); 18 let sectionName = ""; 19 20 /** 21 * Process footer column menu links. 22 * These links are grouped within footer columns and require the 23 * column title to be dynamically extracted from the DOM. 24 */ 25 if (classes.contains("footer-links__link")) { 26 // Locate the wrapper element for the current footer column. 27 const columnContent = el.closest(".footer-column__content"); 28 29 if (columnContent) { 30 // Grab the related <h2> column title. 31 const titleEl = columnContent.parentElement.querySelector(".footer-column__title"); 32 sectionName = titleEl ? titleEl.textContent.trim() : ""; 33 } 34 } 35 36 /** 37 * Process utility menu links (Privacy, Terms, etc.) 38 * These always use the static section name "legal". 39 */ 40 else if (classes.contains("utility-link")) { 41 sectionName = "legal"; 42 } 43 44 /** 45 * Process social media icon links. 46 * These always use the static section name "social". 47 * The value for the analytics link text comes from its title attribute. 48 */ 49 else if (classes.contains("social-link")) { 50 sectionName = "social"; 51 52 // Social icons usually have no text, so fallback to title attribute. 53 linkText = el.getAttribute("title") || linkText; 54 } 55 56 // Fire analytics event with the collected data. 57 try { 58 if (typeof _trackAnalytics === 'function') { 59 const trackingData = { 60 site_events: { footer_element_click: true }, 61 link_text: linkText, 62 section_name: sectionName, 63 link_url: el.href 64 }; 65 console.log('_ta', trackingData); 66 _trackAnalytics(trackingData); 67 } else { 68 console.warn('_trackAnalytics is not defined'); 69 } 70 } catch (error) { 71 console.error('Error tracking analytics:', error); 72 } 73 74 }); 75 } 76 } 77 }; 78 79})(Drupal);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.