1let tpWE = {}; 2(function ($) { 3 'use strict'; 4 tpWE.fn = {}; 5 tpWE.dom = {}; 6 tpWE.data = {}; 7 $(document).ready(function () { 8 tpWE.fn.methodInit(); 9 }) 10 11 tpWE.fn.methodInit = () => { 12 //User Events 13 tpWE.fn.userAuth(); 14 tpWE.fn.getCurrencies(); 15 tpWE.fn.popupViewCounter(); 16 tpWE.fn.customAttributeEventsClicks(); 17 tpWE.fn.freemiumFC(); 18 tpWE.fn.categoryClick(); 19 tpWE.fn.notificationClick(); 20 tpWE.fn.knowMoreClick(); 21 tpWE.fn.courseView(); 22 tpWE.fn.quickPeek(); 23 tpWE.fn.courseAddToCart(); 24 tpWE.fn.joinFinerCircleClick(); 25 tpWE.fn.crispClintClick(); 26 27 tpWE.fn.finerCircle(); 28 29 tpWE.fn.pageView(); 30 //Button Click 31 32 tpWE.fn.generalButtonClickEvent(); 33 34 //Form Submission 35 tpWE.fn.formSubmission(); 36 tpWE.fn.downloadSyllabus(); 37 38 tpWE.fn.sampleModuleAccess(); 39 tpWE.fn.msDashboardEvent(); 40 tpWE.fn.msDashboardViewedIndustryProject(); 41 42 43 tpWE.fn.globalButtonClick(); 44 45 tpWE.fn.order(); 46 // Example Usage: 47 // processCSV("https://www.thetesttribe.com/wp-content/plugins/wc-wp-helper/public/WebEngageOptin-optin.csv"); 48 } 49 50 async function processCSV(url) { 51 const urlParams = new URLSearchParams(window.location.search); 52 if (!urlParams.has('add_whatsapp_opt_in')) { 53 return; 54 } 55 try { 56 const response = await fetch(url); 57 const csvText = await response.text(); 58 const rows = csvText.trim().split("\n"); 59 60 // Extract header and data rows 61 const headers = rows[0].split(",").map(h => h.trim()); 62 const dataRows = rows.slice(1); 63 64 for (let row of dataRows) { 65 let values = row.split(",").map(v => v.trim()); 66 let userData = {}; 67 68 headers.forEach((header, index) => { 69 userData[header] = values[index]; 70 }); 71 72 if (userData["user_id"]) { 73 webengage.user.login(userData["user_id"]); 74 webengage.user.setAttribute('we_whatsapp_opt_in', true); 75 webengage.user.logout(); 76 } 77 } 78 } catch (error) { 79 console.error("Error processing CSV:", error); 80 } 81 } 82 83 84 tpWE.fn.userAuth = () => { 85 const events = [ 86 {cookieName: 'ttt_we_si', eventName: 'Login'}, 87 {cookieName: 'ttt_we_so', eventName: 'Logout'}, 88 { 89 cookieName : 'ttt_we_su', 90 eventName : 'Signup', 91 additionalData: {'Account creation date': tpWE.fn.getCurrentDateFormatted()} 92 }, 93 {cookieName: 'ttt_we_pcr', eventName: 'Password change request'}, 94 {cookieName: 'ttt_we_pcd', eventName: 'Password change Done'} 95 ]; 96 97 events.forEach(event => { 98 const data = tttTopLoad.method.getCookie(event.cookieName); 99 100 let userData = ''; 101 let email = ''; 102 103 if (!data) 104 return; 105 106 if (event.cookieName === 'ttt_we_si') { 107 userData = JSON.parse(data) 108 email = userData.email; 109 } else { 110 email = data; 111 } 112 113 if (email) { 114 const data = {'Email': email, ...event.additionalData}; 115 let loginFlag = true; 116 switch (event.cookieName) { 117 case 'ttt_we_si': 118 let authData = { 119 we_email: email, 120 } 121 if (userData?.first_name) authData['we_first_name'] = userData.first_name; 122 if (userData?.last_name) authData['we_last_name'] = userData.last_name; 123 124 let phone = ''; 125 phone = userData?.billing_phone ? userData.billing_phone : userData?.ms_phone || ''; 126 phone = phone.includes('+') ? phone : userData?.ms_dial_code ? userData.ms_dial_code + phone : phone; 127 if (phone) 128 authData['we_phone'] = userData.phone; 129 130 tpWE.fn.weAuth('login', authData, true) 131 132 loginFlag = false;
133 break; 134 case 'ttt_we_so': 135 tpWE.fn.weAuth('logout') 136 loginFlag = false; 137 break; 138 case 'ttt_we_pcr': 139 loginFlag = false; 140 break; 141 } 142 tpWE.fn.fireEvent(event.eventName, data, loginFlag); 143 document.cookie = `${event.cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`; 144 } 145 }); 146 } 147 148 tpWE.fn.getCurrencies = () => { 149 let symbols = ttt_public_object.currency_symbol; 150 let currencies = [] 151 152 $.each(symbols, function (i, val) { 153 let entity = tpWE.fn.decodeEntities(val) 154 currencies[entity] = i; 155 }); 156 tpWE.data.currencies = currencies; 157 } 158 159 tpWE.fn.popupViewCounter = () => { 160 $(window).on('elementor/popup/show', function (event, id, instance) { 161 // Listen for popup with ID 178072 162 if (id === 177585) { 163 let eventName = 'TQ Sponsor Brochure Popup Open'; 164 tpWE.fn.fireEvent(eventName, {}); 165 } 166 167 }); 168 } 169 tpWE.fn.customAttributeEventsClicks = () => { 170 171 }; 172 tpWE.fn.freemiumFC = () => { 173 let btn = $(".request-for-freemium-membership a") 174 let eventName = "FC Signup Click"; 175 btn.click(function (e) { 176 let clickedLabel = null 177 clickedLabel = $(this).text().trim(); 178 let data = {} 179 data.label = clickedLabel 180 $(this).attr('ttt-we-by', eventName) 181 $(this).find('a').attr('ttt-we-by', eventName) 182 tpWE.fn.fireEvent(eventName, data); 183 }); 184 185 186 $(document).on('click', '#freemium-dynamic-topbar .primary-btn', function (e) { 187 let eventName = 'Freemium Dynamic Topbar: Click'; 188 let message; 189 let btn = $(e.target) 190 let bar = btn.parents('#freemium-dynamic-topbar'); 191 192 if (bar.hasClass('guest-bar')) { 193 message = 'Go to Login'; 194 } else if (bar.hasClass('sso-bar')) { 195 message = 'Verify on SSO'; 196 } else if (bar.hasClass('onboarding-bar')) { 197 message = 'Go to Onboarding Page'; 198 } 199 let data = { 200 url : location.href, 201 message: message 202 }; 203 $(this).attr('ttt-we-by', eventName) 204 tpWE.fn.fireEvent(eventName, data); 205 }) 206 207 let disableMyAccountCardButton = $(".ttt_post_card.ttt_card_disabled .ttt_lock_card_info a") 208 disableMyAccountCardButton.click(function (e) { 209 let data = {} 210 let eventName = "Unlock Attempt"; 211 212 let clickedLabel = null 213 clickedLabel = $(this).text().trim(); 214 data.label = clickedLabel 215 216 let card = $(this).parents('.ttt_post_card'); 217 let title = card.find('.ttt_card_title').text().trim() 218 data.name = title 219 220 let type = card.attr('data-type') 221 let subType = card.attr('data-sub-type') 222 223 $(this).attr('ttt-we-by', eventName) 224 $(this).find('a').attr('ttt-we-by', eventName) 225 tpWE.fn.fireEvent(eventName, data); 226 227 let fields = []; 228 if (type) { 229 fields.push({name: 'Type', value: type, inline: false}) 230 } 231 if (subType) { 232 fields.push({name: 'Sub Type', value: subType, inline: false}) 233 } 234 if (title) { 235 fields.push({name: 'Title', value: title, inline: false}) 236 } 237 238 if (typeof ttt_we_object == 'object') { 239 if (ttt_we_object.hasOwnProperty('_u')) { 240 if (ttt_we_object._u.hasOwnProperty('_name')) 241 fields.push({name: 'Name', value: ttt_we_object._u._name, inline: false}) 242 243 if (ttt_we_object._u.hasOwnProperty('_email')) 244 fields.push({name: 'Email', value: ttt_we_object._u._email, inline: false}) 245 246 if (ttt_we_object._u.hasOwnProperty('_b_email')) 247 fields.push({name: 'Billing Email', value: ttt_we_object._u._b_email, inline: false}) 248 249 if (ttt_we_object._u.hasOwnProperty('_b_phone')) 250 fields.push({name: 'Billing Phone', value: ttt_we_object._u._b_phone, inline: false}) 251 252 let membershipPhone = ''; 253 if (ttt_we_object._u.hasOwnProperty('_ms_dial_code')) 254 membershipPhone = ttt_we_object._u._ms_dial_code; 255 256 if (ttt_we_object._u.hasOwnProperty('_ms_phone')) 257 membershipPhone += ttt_we_object._u._ms_phone; 258 259 if (membershipPhone) 260 fields.push({name: 'Membership Phone', value: membershipPhone, inline: false}) 261 262 } 263 } 264 const domain = window.location.hostname 265 const isLocal = (domain === 'ttt.local') 266 let webhookUrl = (isLocal) ? 'https://discord.com/api/webhooks/1367795608236195980/Jk30oAaNZr6FG0P_Tq_vqGaIs5zcgncpwvuWumbnpe4hbk91RwhPdUPZFYPP-GFYpycI' : 'https://discord.com/api/webhooks/1408014399796678736/ZT7nBX0YBEt_mLz9IQ-ncV9uIpw26P1XvLxp_o-Gvwi-9ThsL6xjzjg7AEGy1jeP9OzR' 267 $.sendDiscordMessage({ 268 webhookUrl: webhookUrl, 269 username : 'Freemium Member', 270 avatarUrl : 'https://www.thetesttribe.com/wp-content/uploads/2024/05/TTT-Ball.png', 271 embeds : [ 272 { 273 title : 'Event : ' + eventName, 274 color : 0x808080, 275 author : { 276 name : 'Freemium Notification', 277 icon_url: 'https://www.thetesttribe.com/wp-content/uploads/2024/05/TTT-Ball.png' 278 }, 279 fields : fields, 280 timestamp: new Date().toISOString() 281 } 282 ], 283 tts : false 284 }); 285 }); 286 } 287 288 tpWE.fn.categoryClick = () => { 289 let category = $('.main_menu_home .menu-item > a, .elementor-widget-nav-menu .elementor-nav-menu a'); 290 const eventName = 'Category Clicked'; 291 category.click(function () { 292 if ($(this).attr('ttt-we-by')) 293 return 294 let clickedLabel = null 295 let parentLabel = null 296 let grandParentLabel = null; 297 clickedLabel = $(this).text().trim(); // Get the clicked menu's text 298 let parent = $(this).parent('.menu-item').parent('.sub-menu').parent('.menu-item').find('> a') // Get the clicked menu's Parent 299 if (parent.length > 0) { 300 parentLabel = parent.text().trim(); 301 let grandParent = parent.parent('.menu-item').parent('.sub-menu').parent('.menu-item').find('> a') // Get the clicked menu's Grand Parent 302 if (grandParent.length > 0) { 303 grandParentLabel = grandParent.text().trim(); 304 } 305 } 306 let data = {} 307 if (grandParentLabel && parentLabel && clickedLabel) { 308 data["Category Name"] = grandParentLabel; 309 data["Sub Category"] = parentLabel; 310 data["Menu Title"] = clickedLabel; 311 } else if (parentLabel && clickedLabel) { 312 data["Category Name"] = parentLabel; 313 data["Sub Category"] = clickedLabel; 314 } else { 315 data["Category Name"] = clickedLabel; 316 } 317 $(this).attr('ttt-we-by', eventName) 318 tpWE.fn.fireEvent(eventName, data); 319 }); 320 } 321 322 tpWE.fn.notificationClick = () => { 323 let args = [ 324 { 325 'class': '.workshop-download', 326 'event': 'Workshop Download Button', 327 }, 328 { 329 'class': '.workshop-waitlist', 330 'event': 'Workshop Waitlist', 331 }, 332 ]; 333 $.each(args, function (i, obj) { 334 let btn = $(`${obj.class}`); 335 let eventName = obj.event; 336 btn.click(function () { 337 let clickedLabel = null 338 clickedLabel = $(this).text().trim(); // Get the clicked menu's text 339 let data = {} 340 data.label = clickedLabel 341 $(this).attr('ttt-we-by', eventName) 342 $(this).find('a').attr('ttt-we-by', eventName) 343 tpWE.fn.fireEvent(eventName, data); 344 }); 345 }) 346 } 347 348 tpWE.fn.knowMoreClick = () => { 349 let knowMore = $('.ttt_we_know_more_course, .ttt_we_know_more_membership'); 350 const eventName = 'Know more clicked'; 351 let label = ''; 352 knowMore.click(function (e) { 353 let _ = $(this); 354 if (_.hasClass('ttt_we_know_more_course')) { 355 label = 'Course'; 356 } else if (_.hasClass('ttt_we_know_more_membership')) { 357 label = 'Membership'; 358 } 359 if (label) { 360 let data = { 361 'Selected': label 362 } 363 $(this).find('a').attr('ttt-we-by', eventName) 364 tpWE.fn.fireEvent(eventName, data); 365 } 366 }); 367 } 368 369 tpWE.fn.courseView = () => { 370 let eventName = 'Product Viewed' 371 let courses = [ 372 { 373 'view' : '.ttt_courses_filter_carousel .ttt_courses_filter_carousel_block a', 374 'wrapper' : { 375 'selector': '.ttt_courses_filter_carousel_block', 376 'relation': 'parents', 377 }, 378 'dataWrapper' : { 379 'selector': '.ttt_courses_filter_carousel_block', 380 'relation': 'parents', 381 }, 382 'courseName' : '.course_title', 383 'courseID' : '', 384 'courseInstructor' : '.carouse_author', 385 'courseCurrency' : '.wc_price .ttt_cb_currency', 386 'courseFee' : '.ttt_cb_amount', 387 'courseCategory' : 'Course', 388 'priceData' : '.ttt_cb_price_wrapper', 389 'courseSubCategory': '', 390 }, 391 { 392 'view' : '.wc_cfm_section .wc_button_secondary', 393 'wrapper' : { 394 'selector': '.wc_cfm_course_result_post_block', 395 'relation': 'parents', 396 }, 397 'dataWrapper' : { 398 'selector': '.wc_cfm_course_result_post_block', 399 'relation': 'parents', 400 }, 401 'courseName' : '.course_title', 402 'courseID' : '', 403 'courseInstructor' : '.carouse_author_name', 404 'courseCurrency' : '.ttt_cb_price .ttt_cb_currency', 405 'courseFee' : '.ttt_cb_amount', 406 'courseCategory' : 'Course', 407 'priceData' : '.ttt_cb_price_wrapper', 408 'courseSubCategory': '', 409 }, 410 ] 411 $.each(courses, function (i, course) { 412 $(document).on({ 413 click: function (e) { 414 let _ = $(this); 415 let blockWrapper = _[`${course.wrapper.relation}`](`${course.dataWrapper.selector}`) 416 let dataWrapper = _[`${course.dataWrapper.relation}`](`${course.dataWrapper.selector}`) 417 418 let productID = dataWrapper.attr('data-ttt-course-product'); 419 productID = (productID) ? atob(productID) : productID; 420 421 let courseID = dataWrapper.attr('data-ttt-course'); 422 courseID = (courseID) ? atob(courseID) : courseID; 423 424 let currencySymbol = blockWrapper.find(`${course.courseCurrency}`).text().trim() 425 let currency = currencySymbol; 426 if (tpWE.data.currencies[currencySymbol]) 427 currency = tpWE.data.currencies[currencySymbol] 428 429 let eventData = { 430 'Product Name' : blockWrapper.find(`${course.courseName}`).text().trim(), 431 'Product ID' : productID, 432 'Product Instructor' : blockWrapper.find(`${course.courseInstructor}`).text().trim(), 433 'Product Currency' : currency, 434 'Product Fee' : blockWrapper.find(`${course.courseFee}`).text().trim(), 435 'Product Category' : 'Course', 436 "Product Sub-category": '', 437 'Course Name' : blockWrapper.find(`${course.courseName}`).text().trim(), 438 "Course ID" : courseID, 439 } 440 // tpWE.fn.fireEvent(eventName, eventData) 441 }, 442 }, `${course.view}`) 443 }); 444 } 445 tpWE.fn.quickPeek = () => { 446 let eventName = 'Quick Peek' 447 let courses = [ 448 { 449 'quickPeek' : '.wc_cfm_course_result_wrapper .wc_carouse_buttons .wc_button_primary', 450 'wrapper' : { 451 'selector': '.wc_cfm_course_result_post_block', 452 'relation': 'parents', 453 }, 454 'dataWrapper' : { 455 'selector': '.wc_cfm_course_result_post_block', 456 'relation': 'parents', 457 }, 458 'courseName' : '.course_title', 459 'CourseID' : '', 460 'courseInstructor' : '.carouse_author_name', 461 'courseCurrency' : '.ttt_cb_price .ttt_cb_currency', 462 'courseFee' : '.ttt_cb_price .ttt_cb_amount', 463 'courseCategory' : 'Course', 464 'priceData' : '.ttt_cb_price_wrapper', 465 'courseSubCategory': '', 466 }, 467 468 ] 469 $.each(courses, function (i, course) { 470 $(document).on({ 471 click: function (e) { 472 let _ = $(this); 473 let blockWrapper = _[`${course.wrapper.relation}`](`${course.dataWrapper.selector}`) 474 let dataWrapper = _[`${course.dataWrapper.relation}`](`${course.dataWrapper.selector}`) 475 476 let productID = dataWrapper.attr('data-ttt-course-product'); 477 productID = (productID) ? atob(productID) : productID; 478 479 let courseID = dataWrapper.attr('data-ttt-course'); 480 courseID = (courseID) ? atob(courseID) : courseID; 481 482 let currencySymbol = blockWrapper.find(`${course.courseCurrency}`).text().trim() 483 let currency = currencySymbol; 484 if (tpWE.data.currencies[currencySymbol]) 485 currency = tpWE.data.currencies[currencySymbol] 486 487 let eventData = { 488 'Product Name' : blockWrapper.find(`${course.courseName}`).text().trim(), 489 'Product ID' : productID, 490 'Product Instructor' : blockWrapper.find(`${course.courseInstructor}`).text().trim(), 491 'Product Currency' : currency, 492 'Product Fee' : blockWrapper.find(`${course.courseFee}`).text().trim(), 493 'Product Category' : 'Course', 494 "Product Sub-category": '', 495 'Course Name' : blockWrapper.find(`${course.courseName}`).text().trim(), 496 "Course ID" : courseID, 497 } 498 $(this).attr('ttt-we-by', eventName) 499 tpWE.fn.fireEvent(eventName, eventData) 500 }, 501 }, `${course.quickPeek}`) 502 }); 503 } 504 505 tpWE.fn.courseAddToCart = () => { 506 const eventName = 'Add to Cart'; 507 let button = $('.wc_thrive_hero_single .ttt_course_buy_now_primary, .
507wc_sticky_header_wrapper .ttt_course_buy_now_sticky') 508 button.click(function (e) { 509 button = $(this); 510 let productId = button.attr('data-product-id'); 511 productId = (productId) ? atob(productId) : productId; 512 let courseId = button.attr('data-course-id'); 513 courseId = (courseId) ? atob(courseId) : courseId; 514 let productTitle = button.attr('data-course-title'); 515 let productInstructor = button.attr('data-course-instructor'); 516 let productCategory = 'Course'; 517 518 let parentBlock = button.parents('.ttt_purchase_course_block') 519 let priceData = parentBlock.find('.wc_price_block') 520 521 let productFee = priceData.find('.wc_price .ttt_cb_amount').text().trim(); 522 productFee = parseFloat(productFee) 523 let currencySymbol = priceData.find(`.ttt_cb_price .wc_price .ttt_cb_currency`).text().trim() 524 let productCurrency = currencySymbol; 525 if (tpWE.data.currencies[currencySymbol]) 526 productCurrency = tpWE.data.currencies[currencySymbol] 527 let data = { 528 'Product id' : productId, 529 'Course id' : courseId, 530 'Product Title' : productTitle, 531 'Product Instructor' : productInstructor, 532 'Product Fee' : productFee, 533 'Product Category' : productCategory, 534 'Product Currency' : productCurrency, 535 'Product Sub-category': '', 536 } 537 538 $(this).attr('ttt-we-by', eventName) 539 tpWE.fn.fireEvent(eventName, data) 540 }); 541 542 } 543 544 tpWE.fn.joinFinerCircleClick = () => { 545 let btn = $('.ttt_membership_button') 546 let eventName = 'Join Finer Circle'; 547 btn.click(function (e) { 548 let wrapper = $(this).parents('.wc_thrive_hero_single') 549 let title = ''; 550 let buyNowButton; 551 if (wrapper.length > 0) { 552 title = wrapper.find('.wc_title').text().trim(); 553 } else { 554 wrapper = $(this).parents('.wc_sticky_header_wrapper') 555 title = wrapper.find('.wc_heading').text().trim(); 556 } 557 buyNowButton = wrapper.find('.wc_button_primary'); 558 let instructor = buyNowButton.attr('data-course-instructor').trim(); 559 let priceData = wrapper.find('.wc_price_block') 560 let productFee = priceData.find('.ttt_cb_price .wc_price .ttt_cb_amount').text().trim() 561 productFee = (productFee) ? parseFloat(productFee) : productFee; 562 let currencySymbol = priceData.find(`.ttt_cb_price .wc_price .ttt_cb_currency`).text().trim() 563 let productCurrency = currencySymbol; 564 if (tpWE.data.currencies[currencySymbol]) 565 productCurrency = tpWE.data.currencies[currencySymbol] 566 let data = { 567 "Product Title" : title, 568 "Product Instructor": instructor, 569 "Product Currency" : productCurrency, 570 "Product Fee" : productFee, 571 } 572 $(this).attr('ttt-we-by', eventName) 573 tpWE.fn.fireEvent(eventName, data) 574 }); 575 } 576 tpWE.fn.changePageViewEvent = (eventName, type = null, subType = null) => { 577 let isEnrolled = $('body').hasClass('ttt-user-enrolled') 578 switch (type) { 579 case 'course': 580 eventName = isEnrolled ? 'Course View' : 'Product View' 581 break; 582 case "Masterclass": 583 case "masterclass": 584 eventName = "Masterclass View"; 585 break; 586 default: 587 } 588 switch (subType) { 589 case 'bundle': 590 case 'workshop': 591 case 'finer-circle': 592 eventName = 'Product View'; 593 break; 594 case 'course': 595 eventName = isEnrolled ? 'Course View' : 'Product View'; 596 break; 597 case 'Module': 598 eventName = 'Module View'; 599 break; 600 case 'Lesson': 601 eventName = 'Lesson View'; 602 break; 603 case 'Quiz': 604 eventName = 'Quiz View'; 605 break; 606 case 'Checkout': 607 eventName = 'Checkout Window'; 608 break; 609 case 'finer-circle/checkout': 610 eventName = 'Checkout Window'; 611 break; 612 default: 613 } 614 return eventName; 615 } 616 tpWE.fn.updatePageViewParameter = async (data, eventName) => { 617 switch (eventName) { 618 case 'Masterclass View': 619 let videoData = await tpWE.fn.getMasterClassVideoVimeoData(true); 620 data = { 621 ...data, 622 ...{ 623 "Duration" : videoData.readableDuration, 624 'Video Title' : data['Page Name'], 625 'Video Link' : videoData.url, 626 'Video Category' : 'Masterclass', 627 'Video Subcategory': ttt_we_object?._masterclass?._type, 628 'Page url' : window.location.href, 629 } 630 } 631 break; 632 default: 633 } 634 return data; 635 } 636 tpWE.fn.pageView = () => { 637 let eventName = "Page viewed"; 638 let pageName = $('head > title').text() 639 if (pageName) 640 pageName = pageName.replace('The Test Tribe - ', '') 641 642 let data = { 643 'Page url': window.location.href, 644 } 645 if (ttt_we_object?._p?._title) data['Page Name'] = ttt_we_object._p._title; 646 if (ttt_we_object?._p?._type) data['Page Type'] = ttt_we_object._p._type; 647 648 if (ttt_we_object?._sub?._type) data['Page Sub Type'] = ttt_we_object._sub._type; 649 eventName = tpWE.fn.changePageViewEvent(eventName, data['Page Type'], data['Page Sub Type']) 650 651 if (ttt_we_object?._u?._type) data['User Type'] = ttt_we_object._u._type; 652 if (ttt_we_object?._u?._email) data['User Email'] = ttt_we_object._u._email; 653 654 if (ttt_we_object?._p_parent?._title) data['Parent Title'] = ttt_we_object._p_parent._title; 655 656 if (ttt_we_object?._course?._title) data['Course Title'] = ttt_we_object._course._title; 657 if (ttt_we_object?._course?._instructor) data['Course Instructor'] = ttt_we_object._course._instructor; 658 659 if (ttt_we_object?._product?._for) data['Product For'] = ttt_we_object._product._for; 660 if (ttt_we_object?._product?._title) data['Product Title'] = ttt_we_object._product._title; 661 if (ttt_we_object?._product?._type) data['Product Type'] = ttt_we_object._product._type; 662 if (ttt_we_object?._product?._tier) data['Product Tier'] = ttt_we_object._product._tier; 663 if (tttTopLoad?.fData?.currency && ttt_we_object?._product?._price?.length) { 664 let currency = tttTopLoad.fData.currency; 665 let priceData = ttt_we_object._product._price.find(p => p.currency === currency) || {}; 666 667 if (priceData.sale_price || priceData.regular_price) { 668 data['Product Price'] = priceData.sale_price || priceData.regular_price; 669 if (data['Product Price']) { 670 data['Product Price'] = parseFloat(data['Product Price']); 671 } 672 } 673 if (priceData.currency) data['Product Currency'] = priceData.currency; 674 } 675 data = tpWE.fn.updatePageViewParameter(data, eventName) 676 677 678 // TODO We can add product view 679 if (data instanceof Promise) { 680 data.then(resolvedData => { 681 tpWE.data.pageViewData = resolvedData; 682 tpWE.fn.fireEvent(eventName, resolvedData); 683 }).catch(error => { 684 console.error('Error resolving promise:', error); 685 }); 686 } else { 687 tpWE.data.pageViewData = data; 688 tpWE.fn.fireEvent(eventName, data); 689 } 690 } 691 692 tpWE.fn.getMasterClassVideoVimeoData = async (readable = false) => { 693 let iFrame = $('.elementor-video-iframe'); 694 if (iFrame.length > 0) { 695 iFrame = iFrame.get(0); // Get the DOM element 696 let videoData = await tpWE.fn.getVimeoVideoData(iFrame);
697 videoData.url = tpWE.fn.getBaseVimeoUrl(iFrame.src); 698 return videoData; 699 } 700 return null; // Optional: return null if no iFrame is found 701 } 702 703 tpWE.fn.getBaseVimeoUrl = (fullUrl) => { 704 // Use URL API to parse the URL 705 const url = new URL(fullUrl); 706 707 // Return only the origin and pathname (removes query parameters and hash) 708 return url.origin + url.pathname; 709 } 710 711 tpWE.fn.getVimeoVideoData = async (iFrame) => { 712 let player = new Vimeo.Player(iFrame); 713 // Await the Promise 714 let duration = await player.getDuration(); // Return the resolved duration 715 let readableDuration = tpWE.fn.secondsToReadableData(duration); 716 return { 717 'duration' : duration, 718 'readableDuration': readableDuration, 719 }; 720 } 721 722 tpWE.fn.secondsToReadableData = (duration) => { 723 // Convert seconds to hh:mm:ss 724 const hours = Math.floor(duration / 3600); 725 const minutes = Math.floor((duration % 3600) / 60); 726 const seconds = Math.floor(duration % 60); 727 728 // Pad with leading zeros if needed 729 return [ 730 hours.toString().padStart(2, '0'), 731 minutes.toString().padStart(2, '0'), 732 seconds.toString().padStart(2, '0') 733 ].join(':'); 734 } 735 736 tpWE.fn.generalButtonClickEvent = () => { 737 let buttons = [ 738 { 739 selector : '.join_finer_circle_membership_clicked', 740 eventName : 'Join Finer Circle Membership Clicked', 741 attributes: {}, 742 data : {}, 743 }, 744 ] 745 $.each(buttons, (i, button) => { 746 $(`${button.selector}`).click(function () { 747 let _ = $(this); 748 let eventName = button.eventName 749 let data = getEventData(buttons[i], _); 750 $(this).attr('ttt-we-by', eventName) 751 tpWE.fn.fireEvent(eventName, data) 752 }); 753 }) 754 let getEventData = (buttonData, TriggerData) => { 755 let data = {} 756 if (buttonData.eventName === 'Join Finer Circle Membership Clicked') { 757 758 } 759 return data; 760 } 761 762 }; 763 764 765 tpWE.fn.formSubmission = () => { 766 let forms = [ 767 { 768 selector : 'form[name="Request a Callback"]', 769 eventName: 'Request Callback', 770 formType : 'elementor', 771 fields : { 772 'First Name' : ['form_fields[first_name]'], 773 "Last Name" : ['form_fields[last_name]'], 774 "Dial Code" : ['form_fields[dial_code]'], 775 "Phone number": ['form_fields[phone]'], 776 "Email" : ['form_fields[email]'], 777 "Product Name": 'Finer Circle', 778 } 779 }, 780 { 781 selector : 'form[name="Download Brochure (Finer Circle)"]', 782 eventName: 'Downlaod FC Brochure', 783 formType : 'elementor', 784 fields : { 785 'First Name' : ['form_fields[first_name]'], 786 "Last Name" : ['form_fields[last_name]'], 787 "Dial Code" : ['form_fields[dial_code]'], 788 "Phone number": ['form_fields[phone]'], 789 "Email" : ['form_fields[email]'], 790 "Product Name": 'Finer Circle', 791 } 792 }, 793 { 794 selector : 'form[name="Home Page Subscribe Community"]', 795 formType : 'elementor', 796 eventName: 'Community Subscribe', 797 fields : { 798 'First Name' : ['form_fields[first_name]'], 799 'Last Name' : ['form_fields[last_name]'], 800 'Pincode' : ['form_fields[pincode]'], 801 'Phone number': ['form_fields[mobile]'], 802 'Email' : ['form_fields[email]'], 803 } 804 }, 805 { 806 selector : 'form[name="Book A Mentor"]', 807 formType : 'elementor', 808 eventName: 'Booked Mentorship', 809 fields : { 810 "Mentor Name" : ['form_fields[mentor_name]'], 811 "First Name" : ['form_fields[first_name]'], 812 "last Name" : ['form_fields[last_name]'], 813 "Email" : ['form_fields[email]'], 814 "Dial Code" : ['form_fields[dial_co
814de]'], 815 "Phone number" : ['form_fields[phone]'], 816 "Designation" : ['form_fields[designation]'], 817 "Years of Experience" : ['form_fields[years_of_experience]'], 818 "Professional Journey" : ['form_fields[professional_journey]'], 819 "Outcome" : ['form_fields[outcome]'], 820 "Tell us your preferred days": ['form_fields[preferred_days][]'], 821 "Tell us your preferred time": ['form_fields[preferred_time][]'], 822 "Time Zone" : ['form_fields[time_zone]'], 823 } 824 }, 825 { 826 selector : 'form[name="Signup for Masterclass"]', 827 formType : 'elementor', 828 eventName: 'Masterclass Registered', 829 fields : { 830 "Masterclass ID" : ['form_fields[master_class_id]'], 831 "Masterclass Title": ['form_fields[master_class_title]'], 832 "Full Name" : ['form_fields[full_name]'], 833 "Email" : ['form_fields[email]'], 834 "Dial Code" : ['form_fields[dial_code]'], 835 "Phone number" : ['form_fields[mobile]'], 836 } 837 }, 838 { 839 selector : '[id^="wpcf7-f42838-"].wpcf7 form', 840 formType : 'cf7', 841 eventName: 'Subscribe', 842 fields : { 843 'First Name': ['first_name'], 844 'Last Name' : ['last_name'], 845 'Email' : ['email'], 846 } 847 }, 848 { 849 selector : '[id^="wpcf7-f824-"].wpcf7 form', 850 formType : 'cf7', 851 eventName: 'Contact us', 852 fields : { 853 'Full Name': ['your-name'], 854 'Email' : ['your-email'], 855 'Message' : ['your-message'], 856 } 857 }, 858 859 ]; 860 $.each(forms, (i, formObject) => { 861 $(`${formObject.selector}`).on("submit", function (event) { 862 let form = $(this); 863 let submit = $(this).find('[type="submit"]') 864 submit.attr('ttt-we-by', formObject.eventName) 865 tpWE.fn.sendOnSubmitFormDataToWE(formObject, form); 866 }) 867 }) 868 } 869 870 tpWE.fn.downloadSyllabus = () => { 871 let btn = $('.ttt-download-syllabus-btn') 872 let eventName = "Download Syllabus"; 873 btn.click(function () { 874 let title = $(this).attr('data-course-title') 875 let id = $(this).attr('data-course') 876 id = (id) ? atob(id) : id 877 let data = { 878 'Course Title': title, 879 'Course ID' : id, 880 "Content Type": 'Syllabus' 881 }; 882 $(this).attr('ttt-we-by', eventName) 883 tpWE.fn.fireEvent(eventName, data) 884 }); 885 } 886 887 888 tpWE.fn.crispClintClick = () => { 889 let eventName = "Crip Chatbot clicked"; 890 let crispButton = $('.crisp-client .cc-1m2mf') 891 crispButton.click(function () { 892 let data = { 893 'Page url': window.location.href 894 } 895 $(this).attr('ttt-we-by', eventName) 896 tpWE.fn.fireEvent(eventName, data) 897 }) 898 }; 899 900 tpWE.fn.finerCircle = () => { 901 let addToCart = () => { 902 let cartBtn = $('.ms-cart-button a'); 903 cartBtn.click(function (e) { 904 e.preventDefault(); 905 let _ = $(this); 906 let parents = _.parents('.ms-cart-button'); 907 let mainWrapper = parents.parent('[data-element_type="container"]') 908 let priceWrapper = mainWrapper.find('.ttt_ms_price_text') 909 let price = priceWrapper.find('.price').text() 910 let currency = priceWrapper.find('.currency').text() 911 let category = ''; 912 if (price == 9999) { 913 category = 'silver' 914 } else if (price == 14999) { 915 category = 'gold' 916 } 917 price = (price) ? parseFloat(price) : price; 918 919 let data = { 920 'Product id' : 4802, 921 'Product Title' : "Finer Circle", 922 'Product Fee' : price, 923 'Product Currency': currency, 924 'Product Category': category, 925 } 926 let eventName = "Add to Cart"; 927 $(this).attr('ttt-we-by', eventName) 928 tpWE.fn.fireEvent(eventName, data) 929 }); 930 } 931 addToCart() 932 933 let checkoutInitiated = () => { 934 let checkoutWrapper = $('.ttt_membership_checkout') 935 let orderNow = checkoutWrapper.find('.ttt_ms_submit') 936 let form = checkoutWrapper.find('.ttt_membership_form') 937 let orderSummary = checkoutWrapper.find('.ttt_order_summary') 938 let config = $.cookie('ms-cart') 939 let tier = (config?.tier) ? config.tier : ''; 940 let price = orderSummary.find('.ttt_ms_title .ttt_price').text(); 941 942 let currency = orderSummary.find('.ttt_ms_total .ttt_currency').text(); 943 944 let subTotal = orderSummary.find('.ttt_ms_subtotal .ttt_price').text(); 945 let tax = orderSummary.find('.ttt_ms_gst .ttt_price').text(); 946 let total = orderSummary.find('.ttt_ms_total .ttt_price').text(); 947 948 orderNow.click(function () { 949 let formData = form.serializeArray() 950 formData = tpWE.fn.getKeyValuePair(formData); 951 $.each(formData, function (i, val) { 952 if (!val) 953 return false;
954 }) 955 956 let tc = checkoutWrapper.find('#ttt_term_condition') 957 if (!tc.is(':checked')) 958 return false; 959 960 let fullName = (formData?.full_name) ? formData.full_name : ''; 961 let email = (formData?.email) ? formData.email : ''; 962 let phone = (formData?.phone) ? formData.phone : ''; 963 let country = (formData?.country) ? formData.country : ''; 964 let city = (formData?.city) ? formData.city : ''; 965 966 let data = { 967 "Category Name" : tier, 968 "Product ID" : 4802, 969 "Product Name" : 'Finer Circle', 970 "Product Currency": currency, 971 "Product Fee" : price, 972 "Subtotal" : subTotal, 973 "GST" : tax, 974 "Total" : total, 975 "Name" : fullName, 976 "Email" : email, 977 "Contact Number" : phone, 978 "Country" : country, 979 "City" : city, 980 } 981 982 let authData = {} 983 if (email) authData.we_email = email; 984 if (fullName) authData.we_first_name = fullName; 985 if (phone) authData.we_phone = phone; 986 tpWE.fn.weAuth('login', authData, false) 987 988 989 let eventName = "Checkout Initiated"; 990 $(this).attr('ttt-we-by', eventName) 991 tpWE.fn.fireEvent(eventName, data) 992 993 994 }); 995 } 996 checkoutInitiated(); 997 998 999 } 1000 1001 tpWE.fn.sampleModuleAccess = () => { 1002 let sampleModule = $('body.ttt_sfwd-lessons_is_sample') 1003 if (sampleModule.length > 0) { 1004 let eventName = "Sample Module Accessed"; 1005 let courseTitle = $('.ttt-course-title.breadcrumb-block'); 1006 let moduleTitle = $('.ttt-current-title.breadcrumb-block'); 1007 let pageURL = $(location).attr('href'); 1008 let data = { 1009 "Course Title": courseTitle, 1010 "Module Title": moduleTitle, 1011 "Page url" : pageURL, 1012 } 1013 tpWE.fn.fireEvent(eventName, data) 1014 } 1015 } 1016 tpWE.fn.msDashboardEvent = () => { 1017 let pathName = location.pathname 1018 if (pathName == '/finer-circle/my-account/') { 1019 let eventName = "My Account Tab View"; 1020 let data = {}; 1021 if (ttt_we_object.hasOwnProperty('_u')) { 1022 if (ttt_we_object._u.hasOwnProperty('_email')) { 1023 data["User Email"] = ttt_we_object._u._email 1024 } 1025 } 1026 1027 let currentPage = $('.ma-tab-title.active') 1028 let currentPageTitle = ''; 1029 if (currentPage.length > 0) { 1030 currentPageTitle = currentPage.text().trim(); 1031 } 1032 if (currentPageTitle) { 1033 data["Tab Title"] = currentPageTitle; 1034 tpWE.fn.fireEvent(eventName + ' - ' + currentPageTitle, data) 1035 } 1036 1037 let tabTitle = $('.ma-tab-title'); 1038 tabTitle.click(function () { 1039 let tabName = $(this).text().trim(); 1040 data["Tab Title"] = tabName; 1041 $(this).attr('ttt-we-by', eventName) 1042 tpWE.fn.fireEvent(eventName + ' - ' + tabName, data) 1043 }); 1044 } 1045 1046 } 1047 1048 tpWE.fn.msDashboardViewedIndustryProject = () => { 1049 let eventName = "Viewed Industry Project" 1050 let btn = $("[data-tab-content='126716'] .elementor-button-text:contains('View Project')") 1051 btn.click(function () { 1052 let href = $(this).parents('.elementor-button').attr('href') 1053 let block = $(this).parents('.ms_industry_project_block') 1054 let title = block.find('.ms_industry_project_title ').text().trim() 1055 let instructor = block.find('.ms_industry_project_instructor').text().trim() 1056 let data = { 1057 "Project ID" : '', 1058 "Project Name" : title, 1059 "Project URL" : href, 1060 "Project Instructor": instructor, 1061 "User Type" : ttt_we_object._u._type, 1062 } 1063 // TODO Pending above value 1064 $(this).attr('ttt-we-by', eventName) 1065 tpWE.fn.fireEvent(eventName, data) 1066 }); 1067 } 1068 1069 tpWE.fn.globalButtonClick = () => { 1070 let buttons = $('a, button'); 1071 buttons.click(function (e) { 1072 let _ = $(this); 1073 setTimeout(function () { 1074 /** 1075 * ttt-we-by stands for we already sended this event 1076 * */ 1077 if (_.attr('ttt-we-by')) 1078 return 1079 1080 let href = ''; 1081 let text = _.text().trim(); 1082 1083 let eventName = tpWE.fn.getGlobalButtonClickEvent(text); 1084 1085 if (_.is('a')) { 1086 href = _.attr('href'); 1087 if (href == 'https://discord.gg/yd2AJQhMxU') { 1088 eventName = 'Join the Community'; 1089 } 1090 } else if (_.is('button')) { 1091 1092 } 1093 let data = { 1094 "Click Text": text, 1095 "Click URL" : href, 1096 "Page Type" : ttt_we_object._p._type, 1097 "Page Title": ttt_we_object._p._title, 1098 "Page URL" : location.href, 1099 } 1100 if (ttt_we_object.hasOwnProperty('_u')) { 1101 data["User Email"] = ttt_we_object._u._email 1102 } 1103 if (ttt_we_object.hasOwnProperty('_sub')) { 1104 if (ttt_we_object._sub.hasOwnProperty('_type')) { 1105 data["Sub Type"] = ttt_we_object._sub._type 1106 } 1107 } 1108 1109 tpWE.fn.fireEvent(eventName, data) 1110 }, 100) 1111 }); 1112 } 1113 1114 tpWE.fn.order = () => { 1115 let orderCheckout = { 1116 billingInputFields: $('.woocommerce-billing-fields__field-wrapper p.validate-required input'), 1117 billingForm : $('form[name="checkout"]'), 1118 }; 1119 $(document).on('click', '.ttt_common_checkout_page #place_order', function (e) { 1120 clickCallback(e) 1121 }); 1122 1123 1124 let clickCallback = (e) => { 1125 let emptyFields = false;
1126 orderCheckout.billingInputFields.each(function () { 1127 if (!$(this).val()) { 1128 emptyFields = true; 1129 } 1130 }); 1131 1132 if (!emptyFields) { 1133 let serializeArray = orderCheckout.billingForm.serializeArray(); 1134 let formData = {}; 1135 let fields = { 1136 'billing_email' : 'we_email', 1137 'billing_first_name': 'we_first_name', 1138 'billing_last_name' : 'we_last_name', 1139 'billing_phone' : 'we_phone', 1140 'billing_country' : 'we_country' 1141 } 1142 let authData = {} 1143 $.each(serializeArray, function (i, fieldObject) { 1144 formData[fieldObject.name] = fieldObject.value; 1145 if (fields.hasOwnProperty(`${fieldObject.name}`)) { 1146 authData[fields[`${fieldObject.name}`]] = fieldObject.value; 1147 } 1148 }) 1149 tpWE.fn.weAuth('login', authData, false) 1150 1151 1152 let cartData = ttt_we_object._cart 1153 let cartProducts = cartData.Products 1154 delete cartData.Products 1155 let eventData = { 1156 'Name' : formData.billing_first_name + ' ' + formData.billing_last_name, 1157 'Email' : formData.billing_email, 1158 'Contact Number': formData.billing_phone, 1159 'Country' : formData.billing_country, 1160 } 1161 eventData = {...eventData, ...cartData}; 1162 1163 let index = 0; 1164 $.each(cartProducts, function (i, val) { 1165 if (index > 0) { 1166 eventData['Product Name'] += ', ' + val['Product Name'] 1167 } else { 1168 eventData['Product Name'] = val['Product Name'] 1169 } 1170 index++; 1171 }) 1172 let eventName = 'Checkout Initated' 1173 tpWE.fn.fireEvent(eventName, eventData) 1174 } 1175 }; 1176 1177 const events = [ 1178 {cookieName: 'ttt_we_oc', eventName: 'Order Created'} 1179 ]; 1180 events.forEach(event => { 1181 let data = tttTopLoad.method.getCookie(event.cookieName); 1182 if (data) { 1183 data = JSON.parse(data); 1184 tpWE.fn.fireEvent(event.eventName, data); 1185 document.cookie = `${event.cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`; 1186 data = tttTopLoad.method.getCookie(event.cookieName); 1187 } 1188 }); 1189 } 1190 1191 tpWE.fn.getGlobalButtonClickEvent = (text) => { 1192 let eventName = 'Click'; 1193 if (text.indexOf("BOOK YOUR SPOT NOW") !== -1) { 1194 eventName = 'Book a Spot'; 1195 } 1196 return eventName; 1197 } 1198 /** 1199 * General Function 1200 * */ 1201 tpWE.fn.fireEvent = (eventName, eventData, loginFlag = true) => { 1202 if (window.location.host === 'thetesttribe.com' || window.location.host === 'www.thetesttribe.com') { 1203 if (typeof webengage !== 'undefined' && webengage) { 1204 webengage.track(eventName, eventData); 1205 } else { 1206 console.error('webengage is undefined'); 1207 } 1208 } else { 1209 console.log({ 1210 eventName: eventName, 1211 eventData: eventData 1212 }); 1213 } 1214 }; 1215 1216 function transformKeysFromWeToNormal(obj) { 1217 return Object.entries(obj).reduce((acc, [key, value]) => { 1218 // Remove 'we_' prefix if exists 1219 let newKey = key.replace(/^we_/, ''); 1220 1221 // Replace remaining underscores with spaces 1222 newKey = newKey.replace(/_/g, ' '); 1223 1224 // Capitalize first letter of each word 1225 newKey = newKey.split(' ') 1226 .map(word => word.charAt(0).toUpperCase() + word.slice(1)) 1227 .join(' '); 1228 1229 acc[newKey] = value; 1230 return acc; 1231 }, {}); 1232 } 1233 1234 tpWE.fn.weAuth = (eventName, data, custom = false) => { 1235 if (window.location.host == 'thetesttribe.com' || window.location.host == 'www.thetesttribe.com') { 1236 if (eventName === 'login') { 1237 if (data?.we_email) { 1238 webengage.user.login(data.we_email); 1239 $.each(data, function (key, val) { 1240 webengage.user.setAttribute(key, val); 1241 }); 1242 webengage.user.setAttribute('we_email_opt_in', true); 1243 webengage.user.setAttribute('we_sms_opt_in', true); 1244 webengage.user.setAttribute('we_whatsapp_opt_in', true); 1245 1246 } 1247 delete data.we_email_opt_in; 1248 delete data.we_sms_opt_in; 1249 delete data.we_whatsapp_opt_ins; 1250 1251 data = transformKeysFromWeToNormal(data) 1252 if (custom) 1253 tpWE.fn.fireEvent("Login", data) 1254 } else if (eventName === 'logout') { 1255 webengage.user.logout(); 1256 } 1257 } else { 1258 console.log('eventName:', eventName); 1259 console.log('eventData:', data); 1260 } 1261 } 1262 1263 tpWE.fn.decodeEntities = (encodedString) => { 1264 let textarea = document.createElement('textarea'); 1265 textarea.innerHTML = encodedString; 1266 return textarea.value; 1267 } 1268 1269 tpWE.fn.getKeyValuePair = (formData) => { 1270 let data = {}; 1271 $(formData).each(function (index, obj) { 1272 if (data[obj.name]) { 1273 // If key exists, append new value with a comma 1274 data[obj.name] += `, ${obj.value}`; 1275 } else { 1276 // Otherwise, assign the first value 1277 data[obj.name] = obj.value; 1278 } 1279 }); 1280 return data; 1281 }; 1282 1283 1284 tpWE.fn.getFormDataForWebEngage = (formDataArray, weFields) => { 1285 let data = {}; 1286 $.each(weFields, (fieldIndex, FieldVal) => { 1287 if (typeof FieldVal === 'string') { 1288 data[fieldIndex] = FieldVal; 1289 } else if (typeof FieldVal === 'object') { 1290 if (FieldVal.length > 1) { 1291 $.each(FieldVal, (key, keyData) => { 1292 if (key > 0) { 1293 data[fieldIndex] += ' '; 1294 } 1295 data[fieldIndex] += formDataArray[FieldVal]; 1296 }) 1297 } else { 1298 data[fieldIndex] = formDataArray[FieldVal]; 1299 } 1300 } 1301 }); 1302 return data; 1303 } 1304 1305 tpWE.fn.sendOnSubmitFormDataToWE = (formObject, form) => { 1306 let eventName = formObject.eventName 1307 if (!form || form.length <= 0) 1308 return false;
1309 let formDataArray = form.serializeArray() 1310 formDataArray = tpWE.fn.getKeyValuePair(formDataArray); 1311 let fields = formObject.fields 1312 let data = tpWE.fn.getFormDataForWebEngage(formDataArray, fields) 1313 tpWE.fn.weAuthOnFormSubmit(data) 1314 tpWE.fn.fireEvent(eventName, data) 1315 } 1316 tpWE.fn.weAuthOnFormSubmit = (data) => { 1317 let firstName, lastName, phone, country, email 1318 if (data.hasOwnProperty('First Name') && data['First Name']) 1319 firstName = data['First Name']; 1320 1321 if (data.hasOwnProperty('Last Name') && data['Last Name']) 1322 lastName = data['Last Name']; 1323 1324 if (!firstName && lastName && data.hasOwnProperty('Full Name') && data['Full Name']) 1325 firstName = data['Full Name']; 1326 1327 if (data.hasOwnProperty('Phone number') && data['Phone number']) { 1328 phone = data['Phone number']; 1329 if (data.hasOwnProperty('Dial Code') && data['Dial Code'] && !phone.includes('+')) 1330 phone = data['Dial Code'] + phone; 1331 } 1332 1333 if (data.hasOwnProperty('Email') && data['Email']) 1334 email = data['Email']; 1335 1336 let authData = {} 1337 if (email) authData.we_email = email; 1338 if (firstName) authData.we_first_name = firstName; 1339 if (lastName) authData.we_last_name = lastName; 1340 if (phone) authData.we_phone = phone; 1341 1342 1343 tpWE.fn.weAuth('login', authData, false) 1344 } 1345 1346 tpWE.fn.callFormSubmissionOutside = (event) => { 1347 let forms = [{ 1348 selector : '.user_form_section .user_form', 1349 formType : 'custom', 1350 eventName: 'Profile Updated', 1351 fields : { 1352 "First Name" : ['first_name'], 1353 "Last Name" : ['last_name'], 1354 "Email" : ['email'], 1355 "Dial Code" : ['ms_dial_code'], 1356 "Phone Number" : ['ms_phone'], 1357 "Date of Birth" : ['ms_dob'], 1358 "Current Company" : ['ms_organisation'], 1359 "Designation" : ['ms_designation'], 1360 "What would describe the team you work at" : ['ms_team_describe'], 1361 "What would best describe you?" : ['ms_self_describe'], 1362 "Years of Experience" : ['ms_years_of_experience'], 1363 "Country" : ['ms_country'], 1364 "City" : ['ms_city'], 1365 "What domain of testing/tech are you interested in learning?": ['ms_domain_interest'], 1366 "What tools/topics are you interested in learning?" : ['ms_tools_interest'], 1367 } 1368 }] 1369 1370 $.each(forms, (i, formObject) => { 1371 if (event === formObject.eventName) { 1372 let form = $(formObject.selector) 1373 tpWE.fn.sendOnSubmitFormDataToWE(formObject, form); 1374 } 1375 }) 1376 } 1377 1378 tpWE.fn.getCurrentDateFormatted = () => { 1379 const date = new Date(); 1380 1381 // Format components 1382 const year = date.getFullYear();
1383 const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed 1384 const day = String(date.getDate()).padStart(2, '0'); 1385 const hours = String(date.getHours()).padStart(2, '0'); 1386 const minutes = String(date.getMinutes()).padStart(2, '0'); 1387 const seconds = String(date.getSeconds()).padStart(2, '0'); 1388 1389 // Timezone offset 1390 const timezoneOffset = -date.getTimezoneOffset(); 1391 const sign = timezoneOffset >= 0 ? "+" : "-"; 1392 const offsetHours = String(Math.floor(Math.abs(timezoneOffset) / 60)).padStart(2, '0'); 1393 const offsetMinutes = String(Math.abs(timezoneOffset) % 60).padStart(2, '0'); 1394 1395 return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${sign}${offsetHours}${offsetMinutes}`; 1396 } 1397 1398 1399 tpWE.fn.fireOnboardingStepCompleted = (step, data) => { 1400 const eventName = `onboarding_step_completed_${step}`; 1401 1402 // Prepare step-specific data 1403 let eventData = { 1404 'Step Number': step, 1405 'Step Data' : data 1406 }; 1407 1408 // Add step-specific information based on the step 1409 switch (step) { 1410 case 1: 1411 eventData['First Name'] = data.first_name || ''; 1412 eventData['Last Name'] = data.last_name || ''; 1413 eventData['Phone'] = data.billing_phone || ''; 1414 break; 1415 case 2: 1416 eventData['Designation'] = data.ms_designation || ''; 1417 eventData['Organization'] = data.ms_current_company || ''; 1418 eventData['Years of Experience'] = data.ms_years_of_experience || ''; 1419 break; 1420 case 3: 1421 eventData['Domain Interests'] = Array.isArray(data.ms_domain_interest) ? data.ms_domain_interest.join(', ') : data.ms_domain_interest || ''; 1422 break; 1423 } 1424 1425 // Fire the WebEngage event 1426 tpWE.fn.fireEvent(eventName, eventData); 1427 }; 1428 1429 tpWE.fn.isJson = (text) => { 1430 if (typeof text !== "string") { 1431 return false; 1432 } 1433 try { 1434 JSON.parse(text); 1435 return true; 1436 } catch (error) { 1437 return false; 1438 } 1439 } 1440 tpWE.fn.unserialize = (data) => { 1441 data = data.split('&'); 1442 var response = {}; 1443 for (var k in data) { 1444 var newData = data[k].split('='); 1445 response[newData[0]] = newData[1]; 1446 } 1447 return response; 1448 } 1449 1450 1451})(jQuery); 1452 1453(function ($) { 1454 $.sendDiscordMessage = function (...args) { 1455 // Data scope for the function 1456 const dataScope = { 1457 webhookUrl: 'string', // Required: Discord webhook URL 1458 content : 'string', // Optional: Message content (text) 1459 username : 'string', // Optional: Custom username for the webhook 1460 avatarUrl : 'string', // Optional: Custom avatar URL for the webhook 1461 embeds : 'array', // Optional: Array of embed objects 1462 tts : 'boolean' // Optional: Text-to-speech flag 1463 }; 1464 1465 let config = {}; 1466 1467 // Handle input: either a single object or multiple variables 1468 if (args.length === 1 && typeof args[0] === 'object') { 1469 config = args[0]; 1470 } else { 1471 config = { 1472 webhookUrl: args[0], 1473 content : args[1] || '', 1474 username : args[2] || undefined, 1475 avatarUrl : args[3] || undefined, 1476 embeds : args[4] || undefined, 1477 tts : args[5] || false 1478 }; 1479 } 1480 1481 // Validate required webhookUrl 1482 if (!config.webhookUrl) { 1483 console.error('Error: Discord webhook URL is required.'); 1484 return; 1485 } 1486 1487 // Prepare payload 1488 const payload = { 1489 content : config.content || '', 1490 username : config.username, 1491 avatar_url: config.avatarUrl, 1492 embeds : config.embeds, 1493 tts : config.tts || false 1494 }; 1495 1496 // Remove undefined properties
1497 Object.keys(payload).forEach(key => payload[key] === undefined && delete payload[key]); 1498 1499 // Send the message using jQuery AJAX 1500 return $.ajax({ 1501 url : config.webhookUrl, 1502 type : 'POST', 1503 contentType: 'application/json', 1504 data : JSON.stringify(payload), 1505 success : function (response) { 1506 console.log('Message sent to Discord successfully.'); 1507 }, 1508 error : function (xhr, status, error) { 1509 console.error('Error sending message to Discord:', error); 1510 } 1511 }); 1512 }; 1513 1514})(jQuery);
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.