1// Valid component tags for analytics tracking 2const VALID_COMPONENT_TAGS = [ 3 'vs-card-2up', 4 'vsr-accordion', 5 'vs-card-3up', 6 'vsr-bottom-panel', 7 'vsr-button', 8 'vsr-carousel-button', 9 'vsr-icon-button', 10 'vsr-link-button', 11 'vsr-media-button', 12 'vsr-text-link', 13 'vsr-card', 14 'vsr-chip', 15 'vsr-button-clear', 16 'vsr-disclaimer', 17 'vsr-dropdown-select', 18 'vsr-filter', 19 'vsr-icon-card', 20 'vsr-product-card', 21 'vsr-tabs', 22 'vsr-title', 23 'vsr-toast', 24 'vsr-video', 25 'card-carousel', 26 'faq-section', 27 'visa-navigation', 28 'visa-footer', 29 'vs-quick-links', 30 'vs-text-image', 31 'visa-footer-navigation', 32 'visa-headline', 33 'visa-hero', 34 'visa-navigation-menu', 35 'visa-tabbed-content', 36 'vs-accordion', 37 'vs-adlibs', 38 'vs-bento-grid', 39 'vs-card-editorial-grid', 40 'vs-content-card-grid', 41 'vs-disclaimer', 42 'vs-promoted-section', 43 'vs-promoted-section-single-media', 44 'vs-promoted-section-dual-media', 45 'vs-promotout', 46 'vs-video-player', 47 'vs-video-modal', 48 'vsr-bottom-panel-v2', 49 'vsr-button-v2', 50 'vsr-carousel-button-v2', 51 'vsr-icon-button-v2', 52 'vsr-link-button-v2', 53 'vsr-media-button-v2', 54 'vsr-text-link-v2', 55 'vsr-chip-v2', 56 'vsr-clear-all-button-v2', 57 'vsr-disclaimer-v2', 58 'vsr-dropdown-select-v2', 59 'vsr-toast-v2', 60]; 61 62function hasValidComponentTag(element) { 63 let currentElement = element; 64 65 while (currentElement && currentElement !== document.body) { 66 const tagName = currentElement.tagName ? currentElement.tagName.toLowerCase() : ''; 67 68 if (VALID_COMPONENT_TAGS.includes(tagName)) { 69 return true; 70 } 71 72 currentElement = currentElement.parentElement; 73 } 74 75 return false; 76} 77 78// Configuration factory function to create reimagineconfig object when needed 79function createReimagineConfig() { 80 return { 81 reimaginefilterElements: ['.vs-filter-tracker', '.vs-tab-filter-btn'], 82 reimagineselectFilterElements: ['.vs-grid-sort-select'], 83 shadowRootRef: [], 84 hoverElements: [], 85 selectElements: [], 86 eventReimagineObject: { 87 clickText: 'getClickText(this)', 88 clickUrl: 89 'this.attributes?.href?.value ? this.attributes?.href?.value : (this.firstChild?.attributes?.href?.value ? this.firstChild?.attributes?.href?.value : (this.parentElement?.attributes?.href?.value ? this.parentElement?.attributes?.href?.value : this.attributes?.getNamedItem(`data-language-url`)?.value))', 90 eventAction: 'getClickTrack(this)', 91 componentType: { 92 selectors: { 93 Header: 94 "($(this).hasClass('visa-navigation-container') && $(this).find('.visa-navigation-nav-item-text') || $(this).hasClass('visa-navigation-tab') || $(this).hasClass('visa-navigation-play-pause-button') || $(this).hasClass('visa-navigation-logo-link') || $(this).hasClass('visa-navigation-search-button') || $(this).hasClass('visa-navigation-search-close-button') || $(this).hasClass('visa-navigation-hamburger-button') || $(this).hasClass('visa-navigation-tab-container') || $(this).hasClass('visa-navigation-secondary-nav-container') || $(this).hasClass('visa-navigation-mobile-link-wrapper') || $(this).hasClass('visa-navigation-mobile-text-link') || $(this).hasClass('visa-navigation-mobile-menu-item-content')) ? 'text': ''", 95 Footer: "$(this).closest('.nav-item').length > 0 && 'link'", 96 'Social Icon': 97 "($(this).hasClass('social-icon') || $(this).hasClass('icon-button')) && 'icon'", 98 AccordionLink: 99 "$(this).parent().hasClass('rich-text-content') || $(this).parent().parent().hasClass('rich-text-content') ? 'link' : ''", 100 Button: 101 "$(this).hasClass('link-button') || $(this).hasClass('analytics-adlib-link') ? 'link' : ($(this).hasClass('button') || $(this).hasClass('analytics-button') || $(this).hasClass('vsr-tab') || $(this).closest('.vs-content-card__load-more-button').length > 0) ? 'button' : ''", 102 Link: "$(this).hasClass('analytics-link') || $(this).hasClass('analytics-footer-button') || $(this).hasClass('quick-link-card-link') ? 'link' : ''", 103 Dropdown: 104 "$(this).hasClass('vs-adlib-dropdown') || $(this).hasClass('vs-adlib-card-item') || $(this).hasClass('language-selector') ? 'dropdown' : ''", 105 Offers: "$(this).closest('vs-offers')", 106 'Rich text': "$(this).closest('.rich-text-content')", 107 Model: "$(this).closest('.vs-modal-parent')", 108 Image: 109 "($(this).hasClass('vsr-product-card__link') || $(this).hasClass('vsr-card__image-container-link')) && $(this).closest('.vs-sct') || $(this).closest('vsr-card').length > 0 ? 'card' : ''", 110 CardCarosuel: 111 "$(this).closest('.vs-card-carousel').length > 0 || $(this).parent().hasClass('card-carousel-container') || $(this).parent().parent().hasClass('card-carousel-container') ? 'card' : ''", 112 'Card Carousel': 113 "$(this).closest('.vs-card-carousel').length > 0 || $(this).parent().hasClass('card-carousel-container') || $(this).parent().parent().hasClass('card-carousel-container') ? 'card' : ''", 114 Text: "$(this).closest('body').length > 0 ? 'text' : ''", 115 }, 116 }, 117 siteSection: "window.location.pathname === '/' ? 'home' : 'others'", 118 imageLabel: 119 "$(this).find('img').length > 0 ? $(this).find('img')[0].getAttribute('alt'): 'NAA'", 120 component: { 121 selectors: { 122 Title: 123 "$(this).closest('.vsr-title-container').length > 0 && getComponentDisplayName($(this).closest('.vsr-title-container').parents().filter(function() { return this.tagName && (this.tagName.toLowerCase().startsWith('vs-') || this.tagName.toLowerCase().startsWith('visa-')) && !this.tagName.toLowerCase().startsWith('vsr-'); }).first()[0]?.tagName)", 124 Card: "$(this).closest('vsr-card').length > 0 && getComponentDisplayName($(this).closest('vsr-card').parents().filter(function() { return this.tagName && (this.tagName.toLowerCase().startsWith('vs-') || this.tagName.toLowerCase().startsWith('visa-')) && !this.tagName.toLowerCase().startsWith('vsr-'); }).first()[0]?.tagName)", 125 Hero: "$(this).closest('.vs-hero-container').length > 0 ? 'hero' : $(this).closest('.vs-hero-container')", 126 'Text Image': 127 "$(this).closest('.visa-text-image').length > 0 && $(this).hasClass('visa-text-image-tab-button') && 'text image'", 128 Adlibs: "$(this).closest('.vs-adlib-container').length > 0 ? 'Adlib' : ''", 129 CardCarosuel: "$(this).hasClass('card-carousel-link') ? 'Card Carousel' : ''", 130 'Card Carousel': "$(this).closest('.vs-card-carousel').length > 0 ? 'Card Carousel' : ''", 131 Accordion: "$(this).hasClass('accordion-header') || $(this).closest('.rich-text-content').length > 0? 'accordion' : ''", 132 'Accordion Link': 133 "$(this).hasClass('accordion-header') && $(this).parent().hasClass('rich-text-content') ? 'link' : ''", 134 'Bento Grid': 135 "$(this).hasClass('button') && $(this).closest('.bentogrid-container').length > 0 ? 'bento grid' : ''", 136 'Editorial Grid': 137 "($(this).hasClass('button-link') || $(this).hasClass('text-link') || $(this).hasClass('title-link')) && ($(this).closest('.editorial-hero-card').length > 0 || $(this).closest('.editorial-grid').length > 0) ? 'editorial grid' : ''", 138 'Content Card Grid': 139 "$(this).closest('.vs-content-card_content-card-grid').length > 0 ? 'Card Grid' : ''", 140 Tabs: "$(this).closest('vsr-tabs').length > 0 && $(this).closest('.vs-content-card_content-card-grid').length > 0 && 'Card Grid'", 141 'Quick Links': "$(this).closest('.quick-link-card').length > 0 && 'Quick link'", 142 Footer: 143 "$(this).hasClass('visa-footer') && $(this).closest('footer').length > 0 ? 'footer' : ''", 144 Header: "$(this).closest('nav').length > 0 ? 'header' : ''", 145 }, 146 }, 147 clickCategory1: { 148 selectors: { 149 "$(this).closest('nav').length > 0 && ($(this).hasClass('visa-navigation-mobile-link-wrapper') || $(this).hasClass('visa-navigation-mobile-text-link') || $(this).hasClass('visa-navigation-mobile-menu-item-content') || $(this).hasClass('visa-navigation-mobile-menu-item-text'))": 150 "$(this).closest('.visa-navigation-mobile-menu').find('.visa-navigation-mobile-menu-title').text().trim() || $(this).closest('.visa-navigation-mobile-section').find('.visa-navigation-mobile-section-title').text().trim() || ''", 151 // "$(this).closest('nav').length > 0": 152 // "$(this).hasClass('visa-navigation-tab') ? $(this).find('.visa-navigation-tab-text').text().trim() : $(this).hasClass('visa-navigation-container') ? $(this).closest('.visa-navigation-tab-container').find('.visa-navigation-active').text().trim() : $(this).hasClass('visa-navigation-heading-container') ? $(this).text().trim() : $(this).hasClass('visa-navigation-mobile-link-wrapper') ? $(this).find('.visa-navigation-mobile-link').text().trim() : $(this).hasClass('visa-navigation-mobile-text-link') ? $(this).find('.visa-navigation-mobile-link').text().trim() : $(this).hasClass('visa-navigation-mobile-menu-item-content') ? $(this).text().trim() : $(this).hasClass('visa-navigation-mobile-menu-item-text') ? $(this).text().trim() : ''", 153 "$(this).closest('.visa-navigation-active').parent().find('.visa-navigation-tab-text')": 154 "!$(this).hasClass('visa-navigation-tab') && $(this).closest('.visa-navigation-active').parent().find('.visa-navigation-tab-text').text().trim()", 155 "$(this).closest('.nav-section').find('.subhead')": 156 "$(this).closest('.nav-section').find('.subhead').text().trim()", 157 "$(this).closest('.vs-adlib-container-wrapper').find('.vs-adlib-heading')": 158 "$(this).closest('.vs-adlib-container-wrapper').find('.vs-adlib-heading').length > 0 ? $(this).closest('.vs-adlib-container-wrapper').find('.vs-adlib-heading').text().trim() : ''", 159 "$(this).hasClass('benefit-panel') || $(this).hasClass('credit-panel')": 160 "$(this).hasClass('benefit-panel') ? $(this).parent().parent().find('.benefit-panel-name').text().trim() : $(this).hasClass('credit-panel') ? $(this).parent().parent().find('.credit-panel-name').text().trim(): ''", 161 "$(this).closest('.vs-hero-button-group').parent().find('.vs-hero-title').text().trim()": 162 "$(this).closest('.vs-hero-button-group').parent().find('.vs-hero-title').data('original-html') ? $(this).closest('.vs-hero-button-group').parent().find('.vs-hero-title').data('original-html').replace(/<[^>]*>?/gm,'').replace(/ /g, ' ') : ''", 163 "$(this).closest('.vs-hero-container').find('.vs-hero-title')": 164 "$(this).closest('.vs-hero-container').find('.vs-hero-title').data('original-html')? $(this).closest('.vs-hero-container').find('.vs-hero-title').data('original-html').replace(/<[^>]*>?/gm,'').replace(/ /g, ' ') : ''", 165 "$(this).closest('section').hasClass('visa-text-image-content-block') && $('.vsr-title-button-group').closest('.visa-text-image-content-wrapper').find('.visa-text-image-tab-nav').length > 0": 166 "$(this).closest('.visa-text-image-content-wrapper').find('.visa-text-image-active').text().trim()", 167 "$(this).closest('.vsr-card').length > 0 && $(this).closest('.vs-content-card__2up-wrapper').length > 0": 168 "$(this).closest('.vs-content-card_content-card-grid').find('.vsr-title-block_container').find('vsr-title').attr('title-block') ? JSON.parse($(this).closest('.vs-content-card_content-card-grid').find('.vsr-title-block_container').find('vsr-title').attr('title-block')).headline : ''", 169 "$(this).closest('.vsr-title-button-group').parent().parent().find('.vsr-title-headline').length > 0": `$(this).parent().parent().parent().parent().parent()[0].className.includes('visa-text-image') && 170 $(this).parent().parent().parent().parent().parent().parent().parent().find('.visa-text-image-active').length > 0 && !$(this).hasClass('visa-text-image-tab-button') ? 171 $($(this).parent().parent().parent().parent().parent().parent().parent().find('.visa-text-image-active').find('.visa-text-image-tab-label')[0]).text().trim() : 172 $(this).parent().parent().parent().parent().parent()[0].className.includes('visa-text-image') && $(this).closest('.vsr-title-button-group').parent().parent().find('.vsr-title-eyebrow').length > 0 ? 173 $(this).closest('.vsr-title-button-group').parent().parent().find('.vsr-title-eyebrow').text().trim() : 174 $(this).parent().parent().parent().parent().parent()[0].className.includes('visa-text-image') && $(this).closest('.vsr-title-button-group').parent().parent().parent().parent().parent().parent().find('.visa-text-image-eyebrow-text').length > 0 ? 175 $(this).closest('.vsr-title-button-group').parent().parent().parent().parent().parent().parent().find('.visa-text-image-eyebrow-text').text().trim() : ''`, 176 "$(this).closest('.vsr-title-button-group').length > 0": 177 "$(this).closest('.vsr-title-button-group').length > 0 ? $(this).closest('.vsr-title-button-group').parent().parent().find('.vsr-title-headline').data('original-html').replace(/<[^>]*>?/gm,'') : ''", 178 "$(this).closest('.accordion-right-column').parent().find('.vsr-title-headline')": 179 "$(this).closest('.accordion-right-column').parent().find('.vsr-title-headline').data('original-html') ? $(this).closest('.accordion-right-column').parent().find('.vsr-title-headline').data('original-html').replace(/<[^>]*>?/gm,'') :''", 180 // "$(this).closest('.quick-link-card').find('.title').text().trim()": 181 // "$(this).closest('.quick-link-card').find('.title').text().trim()", 182 // "$(this).closest('.quick-link-card').attr('data-analytics-title')": 183 // "$(this).closest('.quick-link-card').attr('data-analytics-title')", 184 'getClickCategoryModel(this)': 'getClickCategoryModel(this)', 185 "$(this).closest('.bento-card-content')": 186 "$(this).closest('.bentogrid-container').find('.vsr-title-headline').length > 0 ? $(this).closest('.bentogrid-container').find('.vsr-title-headline').data('original-html').replace(/<[^>]*>?/gm,'') : $(this).closest('.bento-card-content').find('.bento-card-eyebrow').text().trim()", 187 "$(this).closest('.editorial-hero-card')": 188 "$(this).closest('.editorial-hero-card').parent().parent().find('.vsr-title-container').length > 0 ? $(this).closest('.editorial-hero-card').parent().parent().find('.vsr-title-headline').data('original-html').replace(/<[^>]*>?/gm,'') : $(this).closest('.editorial-hero-card').find('.eyebrow').length > 0 ? $(this).closest('.editorial-hero-card').find('.eyebrow').text().trim() : $(this).closest('.editorial-hero-card').find('.title').text().trim()", 189 190 "$(this).closest('.vsr-card').length > 0 && $(this).closest('.vs-content-card__3up-wrapper').length > 0": 191 "$(this).closest('.vs-content-card_content-card-grid').find('vsr-title').attr('title-block') ? JSON.parse($(this).closest('.vs-content-card_content-card-grid').find('vsr-title').attr('title-block')).headline : ''", 192 "$(this).closest('.vsr-card').length > 0 && $(this).closest('.vs-card-editorial-grid').length > 0": 193 "$(this).closest('.vsr-card').closest('.vs-card-editorial-grid').find('vsr-title').attr('title-block') ? JSON.parse($(this).closest('.vsr-card').closest('.vs-card-editorial-grid').find('vsr-title').attr('title-block')).headline : ''", 194 "$(this).closest('.vsr-card').length > 0 && $(this).closest('.vs-card-carousel').length > 0": 195 "$(this).closest('.vs-card-carousel').find('.title-block vsr-title').attr('title-block') ? JSON.parse($(this).closest('.vs-card-carousel').find('.title-block vsr-title').attr('title-block')).headline : ''", 196 "$(this).closest('.vsr-tab-bar').length > 0 && $(this).closest('.vs-content-card_content-card-grid').length > 0": 197 "$(this).closest('.vs-content-card_content-card-grid').find('vsr-title').attr('title-block') ? JSON.parse($(this).closest('.vs-content-card_content-card-grid').find('vsr-title').attr('title-block')).headline : ''", 198 "!$(this).closest('.vsr-tab-bar').length > 0 && $(this).closest('.vs-content-card_content-card-grid').length > 0" : 199 "$(this).closest('.
199vsr-card__content').length > 0 ? $(this).closest('.vsr-card__content').find('.vsr-card__title').text().trim() : ''", 200 "$(this).closest('.carousel-container').parent()": 201 "$(this).closest('.carousel-container').parent().find('.title-block').length ? $(this).closest('.carousel-container').parent().find('.title-block .vsr-title-headline').data('original-html').replace(/<[^>]*>?/gm,'') : ''", 202 "$(this).closest('.vs-card-carousel').length > 0": 203 "$(this).closest('.vs-card-carousel').find('.title-block vsr-title').attr('title-block') ? JSON.parse($(this).closest('.vs-card-carousel').find('.title-block vsr-title').attr('title-block')).headline : ''", 204 "$(this).closest('.vs-content-card_content-card-grid').length > 0 && $(this).closest('.vsr-card__content').length > 0": 205 "$(this).closest('.vs-content-card_content-card-grid').find('vsr-title').attr('title-block') ? JSON.parse($(this).closest('.vs-content-card_content-card-grid').find('vsr-title').attr('title-block')).headline : ''", 206 "$(this).closest('.vs-content-card__load-more-button').length > 0": 207 "$(this).closest('.vs-content-card_content-card-grid').find('vsr-title').attr('title-block') ? JSON.parse($(this).closest('.vs-content-card_content-card-grid').find('vsr-title').attr('title-block')).headline : ''", 208 "$(this).hasClass('visa-footer-panel-right') || $(this).closest('div').hasClass('visa-footer-panel-right')": 209 'Select Country/Region', 210 "$(this).hasClass('vs-adlib-card-item')": 211 "$(this).closest('.vs-adlib-container').find('.vs-adlib-heading').length > 0 ? $(this).closest('.vs-adlib-container').find('.vs-adlib-heading').text().trim() : ''", 212 }, 213 }, 214 clickCategory2: { 215 selectors: { 216 "$(this).closest('.visa-navigation-active').find('.visa-navigation-column01 .visa-navigation-active')": `!$(this).hasClass('visa-navigation-tab') && 217 $(this).hasClass('analytics-col02') || $(this).closest('.visa-navigation-column02').length > 0 ? 218 $(this).closest('.visa-navigation-column02').parent().find('.visa-navigation-active').find('.visa-navigation-heading-container').text().trim() : 219 $(this).hasClass('analytics-col03') || $(this).closest('.visa-navigation-column03').length > 0? 220 $(this).closest('.visa-navigation-column03').parent().find('.visa-navigation-active').find('.visa-navigation-heading-container').text().trim() : 221 ''`, 222 "$(this).closest('section').hasClass('visa-text-image-content-block') && $(this).closest('.visa-text-image-content-wrapper').find('nav').length > 0": 223 "$(this).closest('section').find('vsr-title').attr('title-block') ? JSON.parse($(this).closest('section').find('vsr-title').attr('title-block')).headline : ''", 224 // "$(this).closest('section').find('.vsr-title-container').find('.vsr-title-title-block').text().trim()", 225 // "$(this).closest('.visa-navigation-active').parent().find('.visa-navigation-tab-text')": 226 // "!$(this).hasClass('visa-navigation-tab') && $(this).closest('.visa-navigation-active').parent().find('.visa-navigation-tab-text').text().trim()", 227 "$(this).closest('.vsr-title-button-group').parent().parent().find('.vsr-title-title-block') && !($(this).closest('.visa-text-image-content-wrapper').length > 0)": ` 228 $(this).closest('.vsr-title-button-group').length > 0 && $(this).closest('.vsr-title-button-group').parent().parent().parent().parent()[0].className.includes('visa-text-image') && 229 $(this).closest('.vsr-title-button-group').parent().parent().parent().find('.vsr-title-headline').length > 0 && 230 !$(this).closest('.vsr-title-button-group').parent().parent().parent().parent().parent().find('.visa-text-image-tab-nav').length 231 ? 232 $(this).closest('.vsr-title-button-group').parent().parent().find('.vsr-title-headline').text().trim() 233 : 234 ''`, 235 "$(this).closest('.vsr-title-button-group').parent().parent().parent().parent()[0].className.includes('visa-text-image')": `$(this).closest('.vsr-title-button-group').length > 0 && $(this).closest('.vsr-title-button-group').parent().parent().parent().parent()[0].className.includes('visa-text-image') && 236 $(this).closest('.vsr-title-button-group').parent().parent().parent().find('.vsr-title-headline').length > 0 && 237 $(this).closest('.vsr-title-button-group').parent().parent().parent().parent().parent().find('.visa-text-image-tab-nav').length 238 ? 239 $(this).closest('.vsr-title-button-group').parent().parent().find('.vsr-title-headline').text().trim() 240 : 241 ''`, 242 "$($(this).closest('vs-content-bundle').find('.vs-content-bundle-body')[0]).text()": 243 "$($(this).closest('vs-content-bundle').find('.vs-content-bundle-body')[0]).text()", 244 "$(this.parentElement?.parentElement?.parentNode)?.find('.vs-lead-submenu').text().trim()": 245 "$(this.parentElement?.parentElement?.parentNode)?.find('.vs-lead-submenu').text().trim()", 246 // "$(this).closest('.quick-link-card').find('.description').text().trim()": 247 // "$(this).closest('.quick-link-card').find('.description').text().trim()", 248 "$(this).closest('.bento-card-content')": 249 "$(this).closest('.bento-card-content').find('.bento-card-headline').text().trim()", 250 "$(this).closest('.editorial-hero-card')": 251 "$(this).closest('.editorial-hero-card').find('.title').length > 0 ? $(this).closest('.editorial-hero-card').find('.title').text().trim() : ''", 252 "$(this).closest('.vs-content-card_content-card-grid').length > 0 && $(this).closest('.vsr-card__content').length > 0": 253 "", 254 "$(this).closest('.vs-content-card__load-more-button').length > 0": 255 "$(this).closest('.vs-content-card_content-card-grid').find('.vsr-tab-bar').find('.vsr-tab.active').text()", 256 "$(this).hasClass('vs-adlib-card-item')": 257 "$(this).closest('.vs-adlib-bottom-panel').find('.vs-adlib-panel-name').length > 0 ? $(this).closest('.vs-adlib-bottom-panel').find('.vs-adlib-panel-name').text().trim() : ''", 258 // "$(this).closest('.visa-text-image-content-block').length > 0 && $(this).closest('.vsr-title-container').length > 0": 259 // "$(this).closest('.vsr-title-container').find('.vsr-title-title-block').text().trim()", 260 "$(this).closest('div').hasClass('rich-text-content') && $(this).closest('.accordion-item').find('button').length > 0": 261 "$(this).closest('.accordion-item').find('button').find('.accordion-item-title').text().trim()", 262 // "$(this).closest('section').hasClass('visa-text-image-content-block') && $(this).closest('.vsr-title-button-group').closest('.visa-text-image-content-wrapper').find('.visa-text-image-tab-nav').length > 0": 263 // "$(this).closest('vsr-title').find('.vsr-title-headline').attr('data-original-html').trim()", 264 }, 265 }, 266 }, 267 }; 268} 269 270// Get initial elements for setup - will create config when valid component is clicked 271// const initialConfig = createReimagineConfig(); 272let reimagineclickElements = [ 273 'a', 274 'button',
275 '.analytics-footer-button', 276 '.language-selector', 277 '.vs-hero-moving-arrow', 278 '.visa-navigation-heading-container', 279 '.visa-navigation-hamburger-button', 280 '.visa-navigation-tab-container', 281 '.visa-navigation-secondary-nav-container', 282 '.visa-navigation-mobile-link-wrapper', 283 '.visa-navigation-mobile-text-link', 284 '.visa-navigation-mobile-menu-item-content', 285 '.visa-navigation-mobile-menu-item-text', 286 '.vs-adlib-dropdown', 287 '.vs-adlib-card-item', 288 '.carousel-button', 289 '.card-carousel-link', 290 '.card-title', 291 '.accordion-header', 292]; 293let reimagineshadowRoots = []; 294// START GENAI@GHCOPILOT 295let reimaginefilterElements = ['.vs-filter-tracker', '.vs-tab-filter-btn']; 296let reimagineselectFilterElements = ['.vs-grid-sort-select']; 297 298reimaginefilterElements?.forEach(elem => { 299 $(document).on('click', elem, function (event) { 300 if (!hasValidComponentTag(this)) { 301 return; 302 } 303 304 // Create config and assign window functions only when valid component is clicked 305 const reimagineconfig = createReimagineConfig(); 306 window.getClickCategoryModel = getClickCategoryModel; 307 window.getClickText = getClickText; 308 window.getClickTrack = getClickTrack; 309 window.getComponentDisplayName = getComponentDisplayName; 310 311 let eventObj = JSON.parse(JSON.stringify(reimagineconfig?.eventReimagineObject || {})); 312 reImagineIterate.call(this, eventObj); 313 reImagineSimplify.call(this, eventObj); 314 let filter_event = new CustomEvent('filters_tracking', { 315 detail: { 316 ...eventObj, 317 eventAction: getReimagineFilterType(this), 318 filterDetails: getReimagineFilterInfo(this), 319 }, 320 }); 321 document.dispatchEvent(filter_event); 322 }); 323}); 324 325// START GENAI@CHATGPT4 326reimagineselectFilterElements?.forEach(elem => { 327 $(document).on('change', elem, function (event) { 328 if (!hasValidComponentTag(this)) { 329 return; 330 } 331 332 // Create config and assign window functions only when valid component is clicked 333 const reimagineconfig = createReimagineConfig(); 334 window.getClickCategoryModel = getClickCategoryModel; 335 window.getClickText = getClickText; 336 window.getClickTrack = getClickTrack; 337 window.getComponentDisplayName = getComponentDisplayName; 338 339 let eventObj = JSON.parse(JSON.stringify(reimagineconfig?.eventReimagineObject || {})); 340 reImagineIterate.call(this, eventObj); 341 reImagineSimplify.call(this, eventObj); 342 let filter_event = new CustomEvent('filters_tracking', { 343 detail: { 344 ...eventObj, 345 eventAction: getReimagineFilterType(this), 346 filterDetails: getReimagineFilterInfo(this), 347 }, 348 }); 349 document.dispatchEvent(filter_event); 350 }); 351}); 352// END GENAI@CHATGPT4 353 354const getReimagineFilterInfo = element => { 355 let filterInfo = 'sortBy: text'; 356 if ($(element).hasClass('vs-col-header')) { 357 filterInfo = $(element).data('sort-info'); 358 } else if ( 359 $(element).hasClass('vs-grid-sort-select') || 360 $(element).hasClass('vs-tab-filter-selected') 361 ) { 362 filterInfo = 'sortBy:' + element.value; 363 } 364 return filterInfo; 365}; 366 367const getReimagineFilterType = element => { 368 let filterType = 'dropdown_selected'; 369 if ($(element).hasClass('vs-col-header')) { 370 filterType = 'table_sorted'; 371 } else if ( 372 $(element).hasClass('vs-grid-sort-select') || 373 $(element).hasClass('vs-tab-filter-selected') 374 ) { 375 filterType = 'filter_selected'; 376 } 377 return filterType; 378}; 379 380// END GENAI@GHCOPILOT 381 382function getClickTrack(element, click_event = '') { 383 element = $(element); 384 385 let clickType; 386 387 /** ------------------- 388 * Navigation-related clicks 389 * ------------------- */ 390 if (element.hasClass('toggle-theme')) { 391 let themeToggle = element.closest('nav').find('.toggle-theme'); 392 if (themeToggle.hasClass('light')) clickType = 'light'; 393 if (themeToggle.hasClass('dark')) clickType = 'dark'; 394 } else if (element.hasClass('visa-navigation-play-pause-button')) { 395 let playPause = element.closest('nav').find('.visa-navigation-play-pause-button'); 396 if (playPause.hasClass('play')) clickType = 'play'; 397 if (playPause.hasClass('pause')) clickType = 'pause'; 398 } else if (element.hasClass('visa-navigation-tab')) { 399 clickType = 'header link click'; 400 } else if (element.hasClass('.analytics-button')) { 401 clickType = 'link_click'; 402 } else if (element.hasClass('visa-navigation-logo-link')) { 403 clickType = 'header link click'; 404 } else if (element.hasClass('visa-navigation-search-button')) { 405 clickType = 'header link click'; 406 } else if (element.hasClass('visa-navigation-search-close-button')) { 407 clickType = 'header link click'; 408 } else if (element.hasClass('visa-navigation-link-wrapper')) { 409 clickType = 'header link click'; 410 } else if (element.hasClass('visa-navigation-container')) { 411 clickType = 'header link click'; 412 } else if (element.hasClass('visa-navigation-hamburger-button')) { 413 clickType = 'header link click'; 414 } else if (element.hasClass('visa-navigation-tab-container')) { 415 clickType = 'header link click'; 416 } else if (element.hasClass('visa-navigation-secondary-nav-container')) { 417 clickType = 'header link click'; 418 } else if (element.hasClass('visa-navigation-mobile-link-wrapper')) { 419 clickType = 'header link click'; 420 } else if (element.hasClass('visa-navigation-mobile-text-link')) { 421 clickType = 'header link click'; 422 } else if (element.hasClass('visa-navigation-mobile-menu-item-content') || element.closest('.visa-navigation-mobile-menu-item').length > 0) { 423 clickType = 'header link click'; 424 } else if (element.closest('.nav-item').length > 0 || element.closest('footer').length > 0) { 425 /** ------------------- 426 * Footer & nav-item links 427 * ------------------- */ 428 429 if (click_event == 'exit_click_tracking') { 430 clickType = 'exit link click'; 431 } else { 432 clickType = 'footer link click'; 433 } 434 } else if (element.closest('.vs-content-card_content-card-grid').length > 0) { 435 /** ------------------- 436 * Content card actions 437 * ------------------- */ 438 if (element.closest('vsr-card').length > 0 || element.closest('.carousel-container').length > 0) clickType = 'card_click'; 439 else if (element.closest('.vs-content-card__load-more-button').length > 0) 440 clickType = 'load_more_click'; 441 else if (element.closest('.vs-content-card__view-all-link').length > 0) 442 clickType = 'view_all_click'; 443 else if (element.closest('vsr-tabs').length > 0) clickType = 'tab_click'; 444 } else if (element.hasClass('vs-accordion-button') || element.hasClass('accordion-header')) { 445 /** ------------------- 446 * Accordion actions 447 * ------------------- */ 448 let expanded = element.attr('aria-expanded'); 449 clickType = expanded === undefined ? 'expand' : 'collapse'; 450 } else if (element.hasClass('vs-link-open')) clickType = 'expand'; 451 else if (element.hasClass('vs-link-close')) clickType = 'collapse'; 452 /** ------------------- 453 * Modal actions 454 * ------------------- */ else if ( 455 element.hasClass('modal__show') || 456 element.hasClass('vs-video-play-button') || 457 element.hasClass('vs-share-modal-btn') 458 ) { 459 clickType = 'modal open'; 460 } else if (element.hasClass('visa-icon-close')) clickType = 'modal close'; 461 /** ------------------- 462 * Chat actions 463 * ------------------- */ else if (element.hasClass('vs-sticky-button')) clickType = 'start chat'; 464 else if (element.hasClass('line')) clickType = 'chat preconfigured options'; 465 else if (element.hasClass('visa-document-button')) clickType = 'chat suggested help questions'; 466 else if ( 467 element.hasClass('vs-minimize-icon') && 468 element.closest('.vs-chat-box-element').length > 0 469 ) 470 clickType = 'minimize chat'; 471 /** ------------------- 472 * Carousel navigation 473 * ------------------- */ else if ( 474 element.hasClass('vs-prev') || 475 element.hasClass('vs-next') || 476 element.hasClass('carousel-button prev') || 477 element.hasClass('carousel-button next') 478 ) { 479 clickType = 'carousel navigation'; 480 } else if (element.closest('.quick-links-bar-outer-container').length > 0) { 481 /** ------------------- 482 * Quick Links 483 * ------------------- */ 484 if (element.closest('.quick-link-card').length > 0) clickType = 'quick_link_card_click'; 485 else if (element.hasClass('quick-links-bar-button')) clickType = 'quick_links_navigation'; 486 } else if ( 487 /** ------------------- 488 * Dropdowns 489 * ------------------- */ 490 element.hasClass('vs-adlib-dropdown') || 491 element.hasClass('vs-adlib-dropdown-content') || 492 element.hasClass('vs-adlib-card-item') 493 ) { 494 clickType = 'dropdown_selected'; 495 } else if (element.hasClass('visa-text-image-tab-button')) { 496 /** ------------------- 497 * Tabs 498 * ------------------- */ 499 clickType = 'link_click'; 500 } else if (element.hasClass('vs-hero-moving-arrow')) { 501 /** ------------------- 502 * Hero 503 * ------------------- */ 504 clickType = 'down_arrow_paddle_click'; 505 } else if (element.closest('vsr-card').length > 0 || element.closest('.carousel-container').length > 0) { 506 clickType = 'card_click'; 507 } else if ( 508 /** ------------------- 509 * Generic link/button clicks 510 * ------------------- */ 511 element.hasClass('analytics-adlib-link') || 512 element.hasClass('analytics-link') || 513 element.hasClass('analytics-button') || 514 element.hasClass('link-button') || 515 element.hasClass('button') || 516 element.hasClass('vs-btn') || 517 element.hasClass('vs-link-cta') || 518 element.hasClass('vs-sct') || 519 element.hasClass('vs-share-anchor') || 520 element.hasClass('slide-cta-button') || 521 element.hasClass('btn-xs') || 522 element.hasClass('link-cta') || 523 element.hasClass('vs-d-inline') || 524 element.hasClass('overflower-item selected') || 525 element.hasClass('vs-link-cta-ga4') 526 ) { 527 clickType = 'link_click'; 528 } 529 530 return clickType; 531} 532 533// function getClickTrack(element) { 534// var clickType = 'NAA'; 535// console.log("$(element)",$(element)); 536 537// if ($(element).closest('nav').length > 0) { 538// if ($(element).hasClass('toggle-theme')) { 539// if ($(element).closest('nav').find('.toggle-theme').hasClass('light')) clickType = 'light'; 540// if ($(element).closest('nav').find('.toggle-theme').hasClass('dark')) clickType = 'dark'; 541// }else if ($(element).hasClass('play-pause-button')) { 542// if ($(element).closest('nav').find('.play-pause-button').hasClass('play')) clickType = 'play'; 543// if ($(element).closest('nav').find('.play-pause-button').hasClass('pause')) clickType = 'pause'; 544// } else if($(element).hasClass('visa-navigation-tab')){ 545// clickType = 'header link click'; 546// } 547// } else if ( 548// $(element).closest('.nav-item').length > 0 || 549// $(element).closest('footer').length > 0 550// ) { 551// if ($(element).attr('rel') && $(element).attr('rel').startsWith('noopener noreferrer')) { 552// clickType = 'exit link click'; 553// } else { 554// clickType = 'footer link click'; 555// } 556// } else if ($(element).closest('.vs-content-card_content-card-grid').length > 0) { 557// if ($(element).closest('vsr-card').length > 0) { 558// clickType = 'content_card_click'; 559// } else if ($(element).closest('.vs-content-card__load-more-button').length > 0) { 560// clickType = 'load_more_click'; 561// } else if ($(element).closest('.vs-content-card__view-all-link').length > 0) { 562// clickType = 'view_all_click'; 563// } else if ($(element).closest('vsr-tabs').length > 0) { 564// clickType = 'tab_click'; 565// } 566// } else if ( 567// $(element).hasClass('vs-accordion-button') || 568// $(element).hasClass('accordion-header') 569// ) { 570// let expanded = $(element).attr('aria-expanded'); 571// console.log('expanded', typeof $(element).attr('aria-expanded')); 572// if (expanded == undefined) { 573// clickType = 'expand'; 574// } else { 575// clickType = 'collapse'; 576// } 577// } else if ($(element).hasClass('vs-link-open')) { 578// clickType = 'expand'; 579// } else if ($(element).hasClass('vs-link-close')) { 580// clickType = 'collapse'; 581// } else if ( 582// $(element).hasClass('modal__show') || 583// $(element).hasClass('vs-video-play-button') || 584// $(element).hasClass('vs-share-modal-btn') 585// ) { 586// clickType = 'modal open'; 587// } else if ($(element).hasClass('visa-icon-close')) { 588// clickType = 'modal close'; 589// } else if ($(element).hasClass('vs-sticky-button')) { 590// clickType = 'start chat';
591// } else if ($(element).hasClass('line')) { 592// clickType = 'chat preconfigured options'; 593// } else if ($(element).hasClass('visa-document-button')) { 594// clickType = 'chat suggested help questions'; 595// } else if ( 596// $(element).hasClass('vs-minimize-icon') && 597// $(element).closest('.vs-chat-box-element').length > 0 598// ) { 599// clickType = 'minimize chat'; 600// } else if ($(element).closest('.vs-bot-response').length > 0) { 601// clickType = 'chat link clicks'; 602// } else if ( 603// $(element).hasClass('vs-prev') || 604// $(element).hasClass('vs-next') || 605// $(element).hasClass('carousel-button prev') || 606// $(element).hasClass('carousel-button next') 607// ) { 608// clickType = 'carousel navigation'; 609// } else if ($(element).closest('.quick-links-bar-outer-container').length > 0) { 610// if ($(element).closest('.quick-link-card').length > 0) { 611// clickType = 'quick_link_card_click'; 612// } else if ($(element).hasClass('quick-links-bar-button')) { 613// clickType = 'quick_links_navigation'; 614// } 615// } else if ($(element).hasClass('vs-adlib-dropdown')) { 616// clickType = 'dropdown_selected'; 617// } else if ($(element).hasClass('vs-adlib-dropdown-content')) { 618// clickType = 'dropdown_selected'; 619// } else if($(element).hasClass('visa-text-image-tab-button')){ 620// clickType = 'tab_selected'; 621// } 622// else if ( 623// $(element).hasClass('analytics-adlib-link') || 624// $(element).hasClass('analytics-link') || 625// $(element).hasClass('analytics-button') || 626// $(element).hasClass('link-button') || 627// $(element).hasClass('button') || 628// $(element).hasClass('vs-btn') || 629// $(element).hasClass('vs-link-cta') || 630// $(element).hasClass('vs-sct') || 631// $(element).hasClass('vs-share-anchor') || 632// $(element).hasClass('slide-cta-button') || 633// $(element).hasClass('btn-xs') || 634// $(element).hasClass('link-cta') || 635// $(element).hasClass('vs-d-inline') || 636// $(element).hasClass('overflower-item selected') || 637// $(element).hasClass('vs-link-cta-ga4') 638// ) { 639// clickType = 'link_click'; 640// } 641 642// return clickType; 643// } 644 645function getComponentDisplayName(tagName) { 646 const nameMap = { 647 'vs-card-editorial-grid': 'editorial grid', 648 'vs-content-card-grid': 'Card Grid', 649 'vs-hero': 'Hero', 650 'visa-hero': 'Hero', 651 'vs-accordion': 'Accordion', 652 'vs-bento-grid': 'Bento Grid', 653 'vs-text-image': 'Text Image', 654 'visa-text-image': 'Text Image', 655 'vs-adlibs': 'Adlibs', 656 'vs-card-carousel': 'Card Carousel', 657 'vs-quick-links': 'Quick Links', 658 'vs-promoted-section': 'Promoted Section', 659 'visa-tabbed-content': 'Tabbed Content', 660 'vs-video-player': 'Video Player', 661 'faq-section': 'FAQ Section', 662 'vs-disclaimer': 'Disclaimer', 663 }; 664 665 if (!tagName) return 'title'; 666 667 const cleanName = tagName.toLowerCase(); 668 return ( 669 nameMap[cleanName] || 670 cleanName 671 .replace(/^(vs-|vsr-|visa-)/, '') 672 .replace(/-/g, ' ') 673 .replace(/\b\w/g, l => l.toUpperCase()) || 674 'title' 675 ); 676} 677 678function getClickCategoryModel(element) { 679 var clickType = ''; 680 if ($(element).hasClass('visa-icon-close')) { 681 var vsmodel = $(element).closest('.vs-modal-parent').find('div[data-gtm-component-title]'); 682 var vsmodelVideo = $(element).closest('.vs-modal-container').find('.vs-modal-header'); 683 if (vsmodel && vsmodel.length > 0) { 684 clickType = $(vsmodel[0]).attr('data-gtm-component-title'); 685 } else if (vsmodelVideo && vsmodelVideo.length > 0) { 686 clickType = vsmodelVideo.text().trim(); 687 } 688 } 689 return clickType; 690} 691 692function getClickText(elem) { 693 let clickText = ''; 694 if ($(elem).hasClass('visa-navigation-tab')) { 695 clickText = $(elem).find('.visa-navigation-tab-text').text().trim(); 696 } else if ($(elem).hasClass('visa-navigation-container')) { 697 // Check for nested navigation item text first 698 const navItemText = $(elem).find('.visa-navigation-nav-item-text').text().trim(); 699 if (navItemText) { 700 clickText = navItemText; 701 } else if ($(elem).hasClass('visa-navigation-heading-container')) { 702 clickText = $(elem).text().trim(); 703 } else if ($(elem).hasClass('analytics-col03')) { 704 // For Level 3+ navigation items, get the direct text content 705 clickText = $(elem).text().trim(); 706 } else { 707 // Fallback for other visa-navigation-container elements 708 clickText = $(elem).text().trim(); 709 } 710 } else if ($(elem).hasClass('visa-navigation-mobile-link-wrapper')) { 711 clickText = $(elem).find('.visa-navigation-mobile-link').text().trim(); 712 } else if ($(elem).hasClass('visa-navigation-mobile-text-link')) { 713 clickText = $(elem).find('.visa-navigation-mobile-link').text().trim(); 714 } else if ($(elem).hasClass('visa-navigation-mobile-menu-item-content')) { 715 clickText = $(elem).find('.visa-navigation-mobile-menu-item-text').text().trim(); 716 } else if ($(elem).hasClass('card-carousel-link')) { 717 clickText = $(elem).closest('.card').find('.card-title').text().trim(); 718 } else if ($(elem).hasClass('accordion-header')) { 719 clickText = $(elem).find('.accordion-item-title').text().trim(); 720 } else if ($(elem).hasClass('quick-link-card-link') || $(elem).hasClass('quick-link-card)')) { 721 clickText = $(elem).find('.title').text().trim(); 722 } else if ( 723 $(elem).hasClass('vsr-card__image-container-link') || 724 $(elem).hasClass('vsr-product-card__link') 725 ) { 726 clickText = $(elem).attr('alt-text').trim(); 727 } else if (elem.nodeName === 'SELECT') { 728 clickText = elem.value; 729 } else if (elem.textContent?.length > 0) { 730 clickText = elem.textContent?.trim(); 731 } else if (elem.ariaLabel?.length > 0) { 732 clickText = elem.ariaLabel?.trim(); 733 } else if ($(elem).hasClass('vs-adlib-card-item')) { 734 clickText = $(elem).text().trim(); 735 } else if ($(elem).hasClass('visa-icon-thumbs-up-reverse')) { 736 clickText = 'like'; 737 } else if ($(elem).hasClass('visa-icon-thumbs-down-reverse')) { 738 clickText = 'dislike'; 739 } 740 741 if (clickText.toLocaleLowerCase().startsWith('ongoing chat')) { 742 clickText = 'ongoing chat'; 743 } 744 return clickText; 745}
746reimagineclickElements.forEach(elem => { 747 $(document).on('click', elem, function (event) { 748 if (!hasValidComponentTag(this)) { 749 return; 750 } 751 // Prevent duplicate events by checking if this event was already processed 752 if (event.analyticsProcessed) { 753 return; 754 } 755 event.analyticsProcessed = true; 756 757 // Create config and assign window functions only when valid component is clicked 758 const reimagineconfig = createReimagineConfig(); 759 window.getClickCategoryModel = getClickCategoryModel; 760 window.getClickText = getClickText; 761 window.getClickTrack = getClickTrack; 762 window.getComponentDisplayName = getComponentDisplayName; 763 764 let eventObj = JSON.parse(JSON.stringify(reimagineconfig?.eventReimagineObject || {})); 765 reImagineIterate.call(this, eventObj); 766 reImagineSimplify.call(this, eventObj); 767 const eventDetail = JSON.parse(JSON.stringify(eventObj)); // deep-clone 768 const eventName = 'click_tracking'; 769 if (!$(event.target).hasClass('chat-end-btn')) { 770 let click_event = new CustomEvent(eventName, { 771 detail: { 772 ...eventDetail, 773 eventAction: getClickTrack(this, eventName), 774 }, 775 }); 776 document.dispatchEvent(click_event); 777 } 778 if ( 779 $(this).hasClass('social-icon') || 780 ($(this).attr('href') 781 ? !$(this).attr('href').includes('visa.com') && !$(this).attr('href').includes('/content') 782 : null) 783 ) { 784 let click_event = new CustomEvent('exit_click_tracking', { 785 detail: { 786 ...eventDetail, 787 eventAction: getClickTrack(this, 'exit_click_tracking'), 788 }, 789 }); 790 document.dispatchEvent(click_event); 791 } 792 }); 793}); 794 795// Use addEventListener instead of direct assignment to window.onload 796// This prevents overriding other scripts' window.onload handlers 797window.addEventListener('load', function () { 798 $('.vs-adlib-dropdown').on('click', function (event) { 799 if (!hasValidComponentTag(this)) { 800 return; 801 } 802 803 // Create config and assign window functions only when valid component is clicked 804 const reimagineconfig = createReimagineConfig(); 805 window.getClickCategoryModel = getClickCategoryModel; 806 window.getClickText = getClickText; 807 window.getClickTrack = getClickTrack; 808 window.getComponentDisplayName = getComponentDisplayName; 809 810 let eventObj = JSON.parse(JSON.stringify(reimagineconfig?.eventReimagineObject || {})); 811 reImagineIterate.call(this, eventObj); 812 reImagineSimplify.call(this, eventObj); 813 const eventDetail = JSON.parse(JSON.stringify(eventObj)); // deep-clone 814 const eventName = eventObj.component === 'Chat Assistant' ? 'chat_tracking' : 'click_tracking'; 815 816 if (!$(event.target).hasClass('chat-end-btn')) { 817 let click_event = new CustomEvent(eventName, { 818 detail: { 819 ...eventDetail, 820 eventAction: getClickTrack(this), 821 }, 822 }); 823 document.dispatchEvent(click_event); 824 } 825 }); 826 827 $('.language-selector').on('click', function (event) { 828 if (!hasValidComponentTag(this)) { 829 return; 830 } 831 832 // Create config and assign window functions only when valid component is clicked 833 const reimagineconfig = createReimagineConfig(); 834 window.getClickCategoryModel = getClickCategoryModel; 835 window.getClickText = getClickText; 836 window.getClickTrack = getClickTrack; 837 window.getComponentDisplayName = getComponentDisplayName; 838 839 let eventObj = JSON.parse(JSON.stringify(reimagineconfig?.eventReimagineObject || {})); 840 reImagineIterate.call(this, eventObj); 841 reImagineSimplify.call(this, eventObj); 842 const eventDetail = JSON.parse(JSON.stringify(eventObj)); // deep-clone 843 const eventName = eventObj.component === 'Chat Assistant' ? 'chat_tracking' : 'click_tracking'; 844 845 if (!$(event.target).hasClass('chat-end-btn')) { 846 let click_event = new CustomEvent(eventName, { 847 detail: { 848 ...eventDetail, 849 eventAction: getClickTrack(this), 850 }, 851 }); 852 document.dispatchEvent(click_event); 853 } 854 }); 855 856 $('.accordion-header').on('click', function (event) { 857 if (!hasValidComponentTag(this)) { 858 return; 859 } 860 861 // Create config and assign window functions only when valid component is clicked 862 const reimagineconfig = createReimagineConfig(); 863 window.getClickCategoryModel = getClickCategoryModel; 864 window.getClickText = getClickText; 865 window.getClickTrack = getClickTrack; 866 window.getComponentDisplayName = getComponentDisplayName; 867 868 let eventObj = JSON.parse(JSON.stringify(reimagineconfig?.eventReimagineObject || {})); 869 reImagineIterate.call(this, eventObj); 870 reImagineSimplify.call(this, eventObj); 871 const eventDetail = JSON.parse(JSON.stringify(eventObj)); // deep-clone 872 const eventName = eventObj.component === 'Chat Assistant' ? 'chat_tracking' : 'click_tracking'; 873 874 if (!$(event.target).hasClass('chat-end-btn')) { 875 let click_event = new CustomEvent(eventName, { 876 detail: { 877 ...eventDetail, 878 eventAction: getClickTrack(this), 879 }, 880 }); 881 document.dispatchEvent(click_event); 882 } 883 }); 884}); 885
886reimagineshadowRoots.forEach(shadowRoot => { 887 reimagineclickElements.forEach(elem => { 888 $(shadowRoot)[0] 889 ?.shadowRoot.querySelectorAll(elem) 890 .forEach(item => { 891 item.addEventListener('click', function () { 892 if (!hasValidComponentTag(this)) { 893 return; 894 } 895 896 // Create config and assign window functions only when valid component is clicked 897 const reimagineconfig = createReimagineConfig(); 898 window.getClickCategoryModel = getClickCategoryModel; 899 window.getClickText = getClickText; 900 window.getClickTrack = getClickTrack; 901 window.getComponentDisplayName = getComponentDisplayName; 902 903 let eventObj = JSON.parse(JSON.stringify(reimagineconfig?.eventReimagineObject || {})); 904 reImagineIterate.call(this, eventObj); 905 reImagineSimplify.call(this, eventObj); 906 let click_event = new CustomEvent('click_tracking', { 907 detail: eventObj, 908 }); 909 document.dispatchEvent(click_event); 910 }); 911 }); 912 }); 913}); 914 915document.addEventListener('chat_tracking_internal', e => { 916 document.dispatchEvent(new CustomEvent('chat_tracking', { detail: e.detail })); 917}); 918 919function isCodeString(str) { 920 // Adjust this to fit your naming conventions 921 if (typeof str !== 'string') return false; 922 str = str.trim(); 923 return ( 924 str.startsWith('$(this)') || 925 str.startsWith('getClick') || 926 str.startsWith('window.') || 927 str.includes('this.') || 928 str.includes('$(this)') || 929 str.includes('getClickCategoryModel') 930 ); 931} 932 933function reImagineIterate(obj, ctx) { 934 Object.keys(obj).forEach(key => { 935 const val = obj[key]; 936 if (val && typeof val === 'object' && !Array.isArray(val)) { 937 reImagineIterate(val, ctx || this); 938 } else if (typeof val === 'string') { 939 if (isCodeString(val)) { 940 try { 941 const fn = new Function('return ' + val); 942 const result = fn.call(ctx || this); 943 if (result && result.length <= 0) { 944 delete obj[key]; 945 } else { 946 obj[key] = result; 947 } 948 } catch (e) { 949 console.warn(`Eval failed for key "${key}":`, val, e); 950 // Optionally: delete obj[key]; 951 } 952 } // else: do nothing, leave string as-is 953 } 954 }); 955} 956 957function reImagineSimplify(obj, ctx) { 958 Object.keys(obj).forEach(key => { 959 const val = obj[key]; 960 961 if (val && typeof val === 'object' && !Array.isArray(val) && val.selectors) { 962 let found = ''; 963 const selectorKeys = Object.keys(val.selectors); 964 for (let i = 0; i < selectorKeys.length; i++) { 965 const selectorKey = selectorKeys[i]; 966 const selectorVal = val.selectors[selectorKey]; 967 968 // First check if the selector key condition is met 969 if (isCodeString(selectorKey)) { 970 try { 971 const conditionFn = new Function('return ' + selectorKey); 972 const conditionMet = conditionFn.call(ctx || this); 973 if (!conditionMet) { 974 continue; // Skip this selector if condition is not met 975 } 976 } catch { 977 // Skip this selector if condition evaluation fails (e.g., accessing undefined properties) 978 continue; 979 } 980 } 981 982 // Now evaluate the selector value 983 if (isCodeString(selectorVal)) { 984 try { 985 const fn = new Function('return ' + selectorVal); 986 const evaluated = fn.call(ctx || this); 987 if (evaluated) { 988 found = evaluated; 989 break; 990 } 991 } catch (e) { 992 console.log('simplify error', e); 993 // ignore bad evals 994 } 995 } else { 996 // If it's not code, treat as plain value 997 if (selectorVal && selectorVal.length > 0) { 998 found = selectorVal; 999 break; 1000 } 1001 } 1002 } 1003 obj[key] = found || ''; 1004 } else if (val && typeof val === 'object' && !Array.isArray(val)) { 1005 reImagineSimplify(val, ctx || this); 1006 } else if (typeof val === 'undefined' || val === 'NAA') { 1007 obj[key] = ''; 1008 } 1009 // else, leave as is 1010 }); 1011}
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.