1console.log( "Current Site->" + cdl_cta_global.site ); 2const site_message = "1P " + cdl_cta_global.site + " - 2025"; 3 4 5/** 6 * Function to be check whether a variable is empty or not 7 * 8 * @param {string} value - variable value that needs to be checked. 9 * @returns {bool} returns TRUE if empty. 10 */ 11function emptyCheck(value) { 12 return (value == null || (typeof value === 'string' && value.trim().length === 0)); 13} 14 15 16/** 17 * Function to be check whether a CSS selector is valid selector or not 18 * 19 * @param {string} value - variable value that needs to be checked. 20 * @returns {bool} returns TRUE if empty. 21 */ 22function isValidSelector(selector) { 23 if (typeof selector !== 'string' || selector.trim() === '') { 24 return false; // To Handle empty or non-string inputs 25 } 26 try { 27 if ( jQuery(selector ).length > 0 ) { 28 console.log( "the selector is considered valid by jQuery" ); 29 return true; // If no error, the selector is considered valid by jQuery 30 } 31 32 } catch (e) { 33 console.log( "error indicates an invalid selector" ); 34 return false; // An error indicates an invalid selector 35 } 36} 37 38 39/** 40 * Function to be fired for Recipe Card Click 41 * 42 * @param {string} selector - CSS Selector for Recipe card on the click of which the event will be fired. 43 * @param {string} name_selector - CSS Selector for title of the recipe, should not contain CSS selector mentioned in "selector" parameter, so that it tatgets only the current element, instead of all elements with the same CSS selector. 44 * @param {string} section_selector - CSS Selector for the title of the heading (if dynamic), can be text too (if static). 45 */ 46function recipe_card_click_event_trigger( selector, name_selector, section_selector ) { 47 jQuery(document).on('click', selector, function(event) { 48 let recipe_link = jQuery(this).attr("href"); 49 50 let recipe_name = recipe_link; 51 if ( ! emptyCheck( name_selector ) && jQuery(this).find( name_selector ).length > 0 ) { 52 recipe_name = jQuery(this).find( name_selector ).text(); 53 } 54 55 let section = "Recipe List"; 56 if ( ! emptyCheck( section_selector ) ) { 57 if ( isValidSelector(section_selector) ) { 58 section = jQuery( section_selector ).text().trim() + " " + section; 59 } else if ( "recipe_collection" === section_selector ) { 60 let title = jQuery(this).closest('.collection-child').find("h2.collection-description__title").text(); 61 if ( emptyCheck( title ) ) { 62 title = jQuery( "h1.collection-description__title" ).text(); 63 } 64 section = title.trim() + " " + section; 65 } else if ( "recipe_ideas" === section_selector ) { 66 let title = jQuery(this).closest('.recipes-group-inner').find("h3").text(); 67 if ( emptyCheck( title ) ) { 68 title = "Recipes and Ideas"; 69 } 70 section = title.trim() + " " + section; 71 } else { 72 section = section_selector; 73 } 74 } 75 76 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 77 utag.link({ 78 "tealium_event" : 'recipe_card_click', 79 "click_type" : 'Recipe in' + section.trim(), 80 "click_url" : recipe_link.trim(), 81 "recipe_name" : recipe_name.trim(), 82 }); 83 console.log( site_message + " > recipe_card_click for " + recipe_name.trim() + " in section " + section.trim() + " fired"); 84 } 85 }); 86} 87 88 89 90/** 91 * Function to be fired for Product Card Click 92 * 93 * @param {string} selector - CSS Selector for Product card on the click of which the event will be fired. 94 * @param {string} name_selector - CSS Selector for title of the Product, should not contain CSS selector mentioned in "selector" parameter, so that it tatgets only the current element, instead of all elements with the same CSS selector. 95 * @param {string} section_selector - CSS Selector for the title of the heading (if dynamic), can be text too (if static). 96 */ 97function product_card_click_event_trigger( selector, name_selector, section_selector ) { 98 jQuery(document).on('click', selector, function(event) { 99 let product_link = jQuery(this).attr("href"); 100 101 let product_name = product_link; 102 if ( ! emptyCheck( name_selector ) && jQuery(this).find( name_selector ).length > 0 ) { 103 product_name = jQuery(this).find( name_selector ).text(); 104 } 105 106 let section = "Product List"; 107 if ( ! emptyCheck( section_selector ) ) { 108 if ( isValidSelector(section_selector) ) {
109 section = jQuery( section_selector ).text().trim() + " " + section; 110 } else if ( "product_listing_cat" === section_selector ) { 111 section = jQuery(this).find(".csc-cards__category").text().trim() + " " + section; 112 } else { 113 section = section_selector; 114 } 115 } 116 117 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 118 utag.link({ 119 "tealium_event" : 'product_card_click', 120 "click_type" : 'Product in ' + section.trim(), 121 "click_url" : product_link.trim(), 122 "product_name" : product_name.trim(), 123 }); 124 console.log( site_message + " > product_card_click for " + product_name.trim() + " in section " + section.trim() + " fired"); 125 } 126 }); 127} 128 129 130/** 131 * Function to be fired for Product Card Click 132 * 133 * @param {string} type - click category for the cta click. 134 */ 135function cta_click_event_trigger( type ) { 136 jQuery(document).on('click', ".wp-block-button a.wp-block-button__link", function(event) { 137 let cta_link = jQuery(this).attr("href"); 138 let button_text = jQuery(this).text(); 139 140 let parentWithHeader = jQuery(this).parents().has('h1, h2, h3').first(); 141 let header_text = jQuery(document).attr('title'); 142 if ( parentWithHeader.length > 0 ) { 143 header_text = parentWithHeader.find('h1, h2, h3').first().text(); 144 } 145 146 let event_name = "cta_click"; 147 if ( jQuery(this).parents('[class*="hero"]').length > 0) { 148 event_name = "banner_click"; 149 } 150 151 let click_type = "Button Click"; 152 if ( ! emptyCheck( type ) ) { 153 click_type = type; 154 } 155 156 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 157 utag.link({ 158 "tealium_event" : event_name, 159 "click_type" : click_type, 160 "click_url" : cta_link.trim(), 161 "click_text" : button_text.trim() + " - " + header_text.trim(), 162 }); 163 console.log( site_message + " > " + event_name + " " + button_text.trim() + " - " + header_text.trim() + " event fired" ); 164 } 165 }); 166} 167 168 169/** 170 * Function to be fired for Header navigation Menu 171 * 172 * @param {string} element - jquery element thats been clicked for menu 173 * @param {string} menu_type - Type of Menu clicked 174 */ 175function header_menu_click_event( element, menu_type ) { 176 if ( jQuery(element ).length > 0 ) { 177 let a_link = jQuery(element).attr("href"); 178 let link_text = jQuery(element).text(); 179 let atarget = jQuery(element).attr("target"); 180 181 let event_name = ''; 182 if ( '_blank' === atarget) { 183 event_name = ' external link'; 184 } 185 186 let menu = "mega_menu"; 187 if ( ! emptyCheck( menu_type ) ) { 188 menu = menu_type; 189 } 190 191 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 192 utag.link({ 193 "tealium_event" : 'navigation_click', 194 "click_type" : 'Header Nav ' + menu + event_name + ' Click', 195 "menu_type" : menu, 196 "click_url" : a_link, 197 "click_text" : link_text.trim(), 198 }); 199 console.log( site_message + " > Header Menu " + link_text.trim() + " navigation_click " + menu + event_name + " fired" ); 200 } 201 } 202} 203 204 205/** 206 * Function to be fired for Logo click event 207 * 208 * @param {string} selector - CSS Selector for header Logo. 209 * * @param {string} area - logo area 210 */ 211function logo_click_event_trigger( selector, area ) { 212 jQuery(document).on('click', selector, function(event) { 213 let a_link = jQuery(this).attr("href"); 214 215 let click_type = "Header"; 216 if ( ! emptyCheck( area ) ) { 217 click_type = area; 218 } 219 220 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 221 utag.link({ 222 "tealium_event" : 'navigation_click', 223 "click_type" : click_type + ' Logo Click', 224 "menu_type" : "mega_menu", 225 "click_url" : a_link, 226 "click_text" : click_type + ' Menu Logo Click', 227 }); 228 console.log( site_message + " > " +click_type+ " Menu site Logo navigation_click fired" ); 229 } 230 }); 231} 232 233 234/**
235 * Function to be fired for Social click Events 236 * 237 * @param {string} selector - CSS Selector for Social links 238 * @param {string} area - social media icons area 239 */ 240function social_media_link_click_event_trigger( selector, area ) { 241 jQuery(document).on('click', selector, function(event) { 242 let a_link = jQuery(this).attr("href"); 243 let link_text = jQuery(this).find("span").text(); 244 245 let click_type = "Footer"; 246 if ( ! emptyCheck( area ) ) { 247 click_type = area; 248 } 249 250 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 251 utag.link({ 252 "tealium_event" : "social_share", 253 "click_type" : click_type + ' Social Media Icon Click', 254 "click_url" : a_link, 255 "channel_name" : link_text.trim(), 256 }); 257 console.log( site_message + " > social_share " + link_text.trim() + " click event fired" ); 258 } 259 }); 260} 261 262 263/** 264 * Function to be fired on click of Footer Menu links 265 * 266 * @param {string} selector - CSS Selector for Social links 267 */ 268function footer_menu_click_event_trigger( selector ) { 269 jQuery(document).on('click', selector, function(event) { 270 let a_link = jQuery(this).attr("href"); 271 let link_text = jQuery(this).text(); 272 let event_name = 'external link '; 273 274 let parent_section = jQuery(this).parent("li").parent("ul.sub-menu").parent("li"); 275 276 if ( jQuery(parent_section).length > 0 ) { 277 if ( jQuery(parent_section).hasClass("menu-item-connect") ) { 278 event_name = ''; 279 } else if ( jQuery(parent_section).hasClass("menu-item-campbells-company-2") ) { 280 event_name = 'Corporate Menu external link '; 281 } else if ( jQuery(parent_section).hasClass("menu-item-campbells-brands") ) { 282 event_name = 'Brand Menu external link '; 283 } 284 } else if ( 285 jQuery(this).parent("li").parent("ul#menu-footer-legal").length > 0 || 286 jQuery(this).parent("li").parent("ul#footer_legal").length > 0 287 ) { 288 event_name = 'Legal Menu external link '; 289 } else if ( jQuery(this).parent("div.signup-bottom-links").length > 0 ) { 290 event_name = 'Newsletter Sign Up Popup link '; 291 } else if ( a_link.indexOf(window.location.hostname) !== -1 ) { 292 event_name = ''; 293 } 294 295 if ( 296 ! jQuery(this).parent().hasClass("ot-sdk-show-settings") && 297 ! jQuery(this).parent().hasClass("evidon-option-dialog") && 298 typeof utag !== 'undefined' && 299 typeof utag.link === 'function' 300 ) { 301 utag.link({ 302 "tealium_event" : 'navigation_click', 303 "click_type" : 'Footer Menu ' + event_name + 'Click', 304 "menu_type" : "footer_menu", 305 "click_url" : a_link, 306 "click_text" : link_text.trim(), 307 }); 308 console.log( site_message + " > Footer Menu " + event_name + "navigation link event fired" ); 309 } 310 }); 311} 312 313 314/** 315 * Function to be fired on click of cookie consent link in Footer Menu 316 * 317 * @param {string} selector - CSS Selector for cookie consent link 318 */ 319function footer_cookie_consent_link_event_trigger( selector ) { 320 var consent_url = document.querySelectorAll(selector); 321 consent_url[0].addEventListener("click", function() { 322 let link_text = jQuery(this).text(); 323 324 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 325 utag.link({ 326 "tealium_event" : 'navigation_click', 327 "click_type" : 'Footer Legal Menu consent Popup Click', 328 "menu_type" : "footer_menu", 329 "click_text" : link_text.trim(), 330 }); 331 console.log( site_message + " > Footer Legal Menu consent Popup cta_click fired"); 332 } 333 }); 334} 335 336 337/** 338 * Function to be fired for Header search bar 339 * 340 */ 341function search_click_event_trigger() { 342 jQuery('.js-header-search-toggle, #js-header-search-toggle').on('click', function (event) { 343 let expanded = jQuery(this).attr('aria-expanded'); 344 if ( 'false' == expanded && typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 345 utag.link({ 346 "tealium_event" : 'cta_click', 347 "click_type" : 'Search Form button toggle', 348 "click_text" : 'Search Form Open', 349 }); 350 console.log( site_message + " > Search Form Opened button cta_click event fired" ); 351 } else if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 352 utag.link({ 353 "tealium_event" : 'cta_click', 354 "click_type" : 'Search Form button toggle', 355 "click_text" : 'Search Form Close', 356 }); 357 console.log( site_message + " > Search Form Closed button cta_click event fired" ); 358 } 359 }); 360 361 jQuery(document).on('click', "form .search-submit", function(event) { 362 let search_text = jQuery('input[name="s"]').val(); 363 364 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 365 utag.link({ 366 "tealium_event" : 'search_submit', 367 "click_type" : 'Search Form Submit', 368 "search_term" : search_text.trim(), 369 }); 370 console.log( site_message + " > search_submit: "+search_text+" event fired" ); 371 } 372 }); 373 374 jQuery("#header-search-form").on('click', "form button.search-button", function(event) { 375 let search_text = jQuery('input[name="s"]').val(); 376 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 377 utag.link({ 378 "tealium_event" : 'search_submit', 379 "click_type" : 'Search Form Submit', 380 "search_term" : search_text.trim(), 381 }); 382 console.log( site_message + " > search_submit: "+search_text+" event fired" ); 383 } 384 }); 385 386 jQuery(document).on('click', "form.yxt-SearchBar-form button.js-yext-submit", function(event) { 387 let search_text = jQuery('input[name="query"]').val(); 388 389 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 390 utag.link({ 391 "tealium_event" : 'search_submit', 392 "click_type" : 'Search Form Submit', 393 "search_term" : search_text.trim(), 394 }); 395 console.log( site_message + " > search_submit: "+search_text+" event fired" ); 396 } 397 }); 398 399 jQuery("#header-regular__search-form").on('mousedown', ".yxt-SearchBar-autocomplete ul.yxt-AutoComplete-results li.js-yext-autocomplete-option", function(event) { 400 let search_text = jQuery(this).attr("data-value"); 401 402 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 403 utag.link({ 404 "tealium_event" : 'search_submit', 405 "click_type" : 'Search Form Submit: autocomplete selected', 406 "search_term" : search_text.trim(), 407 }); 408 console.log( site_message + " > view_search_results: "+search_text+" autocomplete selected event fired" ); 409 } 410 }); 411 412 jQuery(document).on('click', "form.yxt-SearchBar-form button.js-yxt-SearchBar-clear", function(event) { 413 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 414 utag.link({ 415 "tealium_event" : 'cta_click', 416 "click_type" : 'Search Form clear', 417 "click_text" : 'Delete', 418 }); 419 console.log( site_message + " > Search Form clear cta_click event fired" ); 420 } 421 }); 422 423} 424 425 426/**
427 * Function to trigger on newsletter Signup related CTA clicks 428 */ 429function newsletter_singup_cta_event_trigger() { 430 431 jQuery(document).on('click', "button.header-newsletter-button, button.footer-newsletter-button", function(event) { 432 let button_class = jQuery(this).attr('class'); 433 let button_position = "Header"; 434 if ( button_class.indexOf("footer") !== -1 ) { 435 button_position = "Footer"; 436 } 437 438 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 439 utag.link({ 440 "tealium_event" : 'newsletter_signup_started', 441 "click_type" : button_position + ' Newsletter Sign Up Button Clicked', 442 "click_text" : 'Sign Up', 443 }); 444 console.log( site_message + " > " + button_position + " newsletter_signup_started event fired" ); 445 } 446 }); 447 448 jQuery(document).on('click', "#newsletter-dialog .dialog-close", function(event) { 449 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 450 utag.link({ 451 "tealium_event" : 'cta_click', 452 "click_type" : 'Newsletter Sign Up Pop-up Close button clicked', 453 "click_text" : 'Newsletter Pop-up Close', 454 }); 455 } 456 }); 457 458 459 footer_menu_click_event_trigger( "form#simplenewletterform .signup-bottom-links a" ); 460 461} 462 463 464/** 465 * Function to trigger on newsletter Signup submit events 466 */ 467function newsletter_singup_submit_event_trigger() { 468 var maxChecks = 30; // Maximum number of checks 469 var checkInterval = 1000; // Interval in milliseconds 470 471 document.forms['simplenewletterform'].addEventListener('submit', (event) => { 472 let timeoutId; 473 474 const observer = new MutationObserver((mutations) => { 475 mutations.forEach((mutation) => { 476 if ( mutation.target.classList.contains('wds-esc-submission-success') ) { 477 observer.disconnect(); 478 clearTimeout(timeoutId); // Clear the timeout 479 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 480 utag.link({ 481 "tealium_event" : 'newsletter_signup_completed', 482 "click_type" : 'Newsletter Sign Up Form Email Submit', 483 "click_text" : "Submit", 484 }); 485 console.log( site_message + " > newsletter_signup_completed event fired" ); 486 } 487 } 488 }); 489 }); 490 491 observer.observe(document.querySelector('.wds-esc-form-container'), { attributes: true, attributeFilter: ['class'] }); 492 493 timeoutId = setTimeout(() => { 494 observer.disconnect(); 495 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 496 utag.link({ 497 "tealium_event" : 'newsletter_signup_error', 498 "click_type" : 'Newsletter Sign Up Form Email Submit Error occurred', 499 "click_text" : "Submit", 500 }); 501 console.log( site_message + " > newsletter_signup_error event fired" ); 502 } 503 }, maxChecks * checkInterval); // Adjust the timeout based on your interval and maxChecks 504 }); 505} 506 507 508/** 509 * Function to trigger on newsletter Signup submit related events 510 */ 511function newsletter_singup_after_submit_cta_event_trigger() { 512 recipe_selector = ".signup-subscribe-step2 .signup-recipe-items .signup-item a"; 513 title_selector = ".card-text"; 514 sect_title_selector = "Newsletter Signup Thankyou Recommended Recipes"; 515 516 recipe_card_click_event_trigger( recipe_selector, title_selector, sect_title_selector ); 517 518 519 jQuery(document).on('click', ".signup-subscribe-step2 .signup-social-share li a", function(event) { 520 let a_link = jQuery(this).attr("href"); 521 channel_name = ''; 522 if ( a_link.indexOf("facebook") !== -1 ) { 523 channel_name = "Facebook"; 524 } else if ( a_link.indexOf("instagram") !== -1 ) { 525 channel_name = "Instagram"; 526 } else if ( a_link.indexOf("youtube") !== -1 ) { 527 channel_name = "Youtube"; 528 } else if ( a_link.indexOf("pinterest") !== -1 ) { 529 channel_name = "Pinterest"; 530 } else if ( a_link.indexOf("tiktok") !== -1 ) { 531 channel_name = "Tiktok"; 532 } 533 534 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 535 utag.link({ 536 "tealium_event" : "social_share", 537 "click_type" : 'Newsletter Signup Thankyou Social Media Click', 538 "click_url" : a_link, 539 "channel_name" : channel_name, 540 }); 541 console.log( site_message + " > Newsletter Signup Thankyou social_share event " + channel_name + " fired" ); 542 } 543 }); 544} 545 546 547 548 549/**
550 * Function to check the type of carousel based on the block class 551 */ 552function find_slider_type(element) { 553 let slider_type = "Carousel"; 554 if ( jQuery(element).closest(".js-product-line-hero").length > 0 ) { 555 slider_type = "Product Carousel"; 556 } else if ( jQuery(element).closest(".product-gallery").length > 0 ) { 557 slider_type = "Product Carousel"; 558 } else if ( jQuery(element).closest(".js-related-content").length > 0 ) { 559 let slider_items = jQuery(element).closest(".tns-outer").find(".tns-inner .tns-item"); 560 let a_title = jQuery(slider_items[0]).attr("class"); 561 let slider_title = a_title.toLowerCase(); 562 if ( slider_title.indexOf("recipe") !== -1 ) { 563 slider_type = "Recipe Carousel"; 564 } else if ( slider_title.indexOf("product") !== -1 ) { 565 slider_type = "Product Carousel"; 566 } else { 567 slider_type = "Content Carousel"; 568 } 569 } else if ( jQuery(element).closest(".js-content-carousel-block").length > 0 ) { 570 slider_type = "Content Carousel"; 571 } else if ( jQuery(element).closest(".js-featured-content-block").length > 0 ) { 572 page_title = jQuery(document).attr('title'); 573 slider_type = page_title + " Featured Carousel"; 574 } else if ( jQuery(element).closest(".hero-carousel").length > 0) { 575 page_title = jQuery(document).attr('title'); 576 slider_type = page_title + " Hero Carousel"; 577 } 578 579 return slider_type; 580} 581 582 583/** 584 * Function to be fired for Carousel navigation clicks 585 * 586 */ 587function slider_nav_click_event_trigger() { 588 589 jQuery(document).on('click', ".tns-controls button[data-controls=next]", function(event) { 590 let slider_type = find_slider_type( jQuery(this) ); 591 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 592 utag.link({ 593 "tealium_event" : 'cta_click', 594 "click_type" : slider_type + ' Navigation click', 595 "click_text" : 'Right Arrow (Next) click', 596 }); 597 console.log( site_message + " > " + slider_type + " Navigation Next cta_click fired"); 598 } 599 }); 600 601 jQuery(document).on('click', ".tns-controls button[data-controls=prev]", function(event) { 602 let slider_type = find_slider_type( jQuery(this) ); 603 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 604 utag.link({ 605 "tealium_event" : 'cta_click', 606 "click_type" : slider_type + ' Navigation click', 607 "click_text" : 'Left Arrow (Previous) click', 608 }); 609 console.log( site_message + " > " + slider_type + " Navigation Previous cta_click fired"); 610 } 611 }); 612 613 jQuery(document).on('click', ".tns-outer button[data-action=stop]", function(event) { 614 let slider_type = find_slider_type( jQuery(this) ); 615 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 616 utag.link({ 617 "tealium_event" : 'cta_click', 618 "click_type" : slider_type + ' Navigation click', 619 "click_text" : 'Pause button click', 620 }); 621 console.log( site_message + " > " + slider_type + " Navigation Pause cta_click fired"); 622 } 623 }); 624 625 jQuery(document).on('click', ".tns-outer button[data-action=start]", function(event) { 626 let slider_type = find_slider_type( jQuery(this) ); 627 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 628 utag.link({ 629 "tealium_event" : 'cta_click', 630 "click_type" : slider_type + ' Navigation click', 631 "click_text" : 'Play button click', 632 }); 633 console.log( site_message + " > " + slider_type + " Navigation Play cta_click fired"); 634 } 635 }); 636 637 jQuery(document).on('click', ".tns-outer .tns-nav button", function(event) { 638 let slider_type = find_slider_type( jQuery(this) ); 639 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 640 utag.link({ 641 "tealium_event" : 'cta_click', 642 "click_type" : slider_type + ' Navigation click', 643 "click_text" : 'Nav Dot button click', 644 }); 645 console.log( site_message + " > " + slider_type + " Navigation Nav dot cta_click fired"); 646 } 647 }); 648} 649 650 651/**
652 * Function to be fired for Carousel navigation clicks 653 */ 654function faq_click_event_trigger() { 655 jQuery(document).on('click', ".csc-accordion button.accordion-header, .accordion button.accordion-header", function(event) { 656 let click_text = jQuery(this).text(); 657 let parent_cls = jQuery(this).parents().first().attr('class'); 658 let click_type = "FAQ Header Tab"; 659 if ( parent_cls.indexOf("faq-accordion") !== -1 ) { 660 click_type = "FAQ Tab"; 661 } 662 663 let expanded = jQuery(this).attr('aria-expanded'); 664 665 if ( 'true' == expanded && typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 666 utag.link({ 667 "tealium_event" : 'faq_click', 668 "click_type" : click_type + ' clicked', 669 "click_text" : "faq-" + click_text.trim() + "-open", 670 }); 671 console.log( site_message + " > " + click_type + " click open event fired"); 672 } 673 }); 674} 675 676 677 678/** 679 * Function to listen to user made video events triggers on a video player 680 */ 681function recipe_video_player_events() { 682 document.addEventListener('DOMContentLoaded', function() { 683 var mobileVideo = document.getElementById('custom-widget-mobile-video'); 684 var desktopVideo = document.getElementById('custom-widget-desktop-video'); 685 var milestones = [25, 50, 75, 90, 100]; 686 687 // Add event listeners to the video elements 688 if (mobileVideo) { 689 mobileVideo.addEventListener('play', function() { 690 resetMilestones(mobileVideo, milestones); 691 fireUtagEvent(mobileVideo, 'mobile', 'video_start'); 692 mobileVideo.milestoneChecker = startCheckingMilestones(mobileVideo, milestones); 693 }); 694 mobileVideo.addEventListener('pause', function() { 695 fireUtagEvent(mobileVideo, 'mobile', 'video_pause'); 696 clearInterval(mobileVideo.milestoneChecker); 697 }); 698 mobileVideo.addEventListener('ended', function() { 699 fireUtagEvent(mobileVideo, 'mobile', 'video_complete'); 700 clearInterval(mobileVideo.milestoneChecker); 701 }); 702 } 703 704 if (desktopVideo) { 705 desktopVideo.addEventListener('play', function() { 706 resetMilestones(desktopVideo, milestones); 707 fireUtagEvent(desktopVideo, 'desktop', 'video_start'); 708 desktopVideo.milestoneChecker = startCheckingMilestones(desktopVideo, milestones); 709 }); 710 desktopVideo.addEventListener('pause', function() { 711 fireUtagEvent(desktopVideo, 'desktop', 'video_pause'); 712 clearInterval(desktopVideo.milestoneChecker); 713 }); 714 desktopVideo.addEventListener('ended', function() { 715 fireUtagEvent(desktopVideo, 'desktop', 'video_complete'); 716 clearInterval(desktopVideo.milestoneChecker); 717 }); 718 } 719 }); 720} 721 722/** 723 * Function to reset the percentage of video played to 0% 724 */ 725function resetMilestones(video, milestones) { 726 for (var i = 0; i < milestones.length; i++) { 727 video[`milestone${milestones[i]}`] = false; 728 } 729} 730 731/** 732 * Function to fire Tealium event on video event triggers 733 */ 734function fireUtagEvent(video, videoType, videoState) { 735 var pageName = document.title; 736 var videoDuration = video.duration; 737 var currentPercentage = Math.round((video.currentTime / videoDuration) * 100); 738 739 // Define the event data 740 var utagEvent = { 741 tealium_event: videoState, 742 video_title: pageName, 743 video_percent: currentPercentage, 744 }; 745 746 // Fire the utag event 747 if ( typeof utag !== 'undefined' && typeof utag.link === 'function' ) { 748 utag.link(utagEvent); 749 console.log( site_message + " > " + videoState + " event fired at percent " + currentPercentage ); 750 } 751} 752 753/** 754 * Function to actively check the percentage of video played 755 */
756function startCheckingMilestones(video, milestones) { 757 var checkInterval = 100; // Check every 100 milliseconds 758 return setInterval(function() { 759 checkMilestones(video, milestones); 760 }, checkInterval); 761} 762 763/** 764 * Function to check the percentage of video played and fire tealium event 765 */ 766function checkMilestones(video, milestones) { 767 var videoDuration = video.duration; 768 var currentPercentage = Math.round((video.currentTime / videoDuration) * 100); 769 770 for (var i = 0; i < milestones.length; i++) { 771 772 if (currentPercentage >= milestones[i] - 1 && currentPercentage <= milestones[i] + 1 && !video[`milestone${milestones[i]}`]) { 773 video[`milestone${milestones[i]}`] = true; // Mark milestone as completed 774 fireUtagEvent(video, "", 'video_progress'); 775 } 776 } 777} 778
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.