1(function() { 2 function KatalonHubspot() { 3 // function send data to Hubspot 4 this.sendToHubspot = function(data, callback) { 5 jQuery.ajax({ 6 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/update-contact', 7 type: 'POST', 8 contentType: 'application/json', 9 dataType: 'json', 10 data: data, 11 success: function(obj) { 12 // callback function whenever Hubspot tracking send successfully 13 if (callback && typeof(callback) == "function") { 14 callback(); 15 } 16 }, 17 error: function(xhr, textStatus, errorThrown) { 18 console.error('[KatalonHubspot] update-contact failed', xhr.status, textStatus, errorThrown); 19 } 20 }); 21 } 22 23 // function send data to Hubspot createOrUpdate 24 this.sendToHubspotViaCreateOrUpdate = function(data, callback) { 25 jQuery.ajax({ 26 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 27 type: 'POST', 28 contentType: 'application/json', 29 data: data, 30 success: function(resp) { 31 if (callback && typeof(callback) == "function") { 32 callback(); 33 } 34 }, 35 error: function(xhr, textStatus, errorThrown) { 36 console.error('[KatalonHubspot] create-contact failed', xhr.status, textStatus, errorThrown); 37 } 38 }); 39 } 40 41 // function tracking user use Testops is the first product 42 this.trackUserUseTOFirst = function(data, callback) { 43 jQuery.ajax({ 44 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 45 type: 'POST', 46 contentType: 'application/json', 47 dataType: 'json', 48 data: data, 49 success: function(resp) { 50 //console.log('Get contact successfully'); 51 if (!resp['status'] && resp['status'] !== 'error') { 52 // get contact successfully 53 54 var dataSend = { 55 email: resp['properties']['email']['value'], 56 properties: { 57 to_product_registration: 'Signed In' 58 } 59 }; 60 // check property KR_product_registration and KS_product_registration 61 if (!resp['properties']['kr_product_registration'] && !resp['properties']['activation_status']) { 62 // not yet use KR or KS 63 dataSend.properties.to_first_product = 'Yes'; 64 } 65 66 //console.log(data_send); 67 katalonHubspot.sendToHubspot(JSON.stringify(dataSend), callback); 68 } else { 69 // console.log('something error'); 70 // get contact error -> do nothing 71 callback(); 72 } 73 } 74 }); 75 } 76 77 // function tracking user submit download report 2022 form 78 this.trackUserDownloadReport2022 = function(data, callback) { 79 var dataGetContact = { 80 email: data["email"] 81 }; 82 83 // format first and last name 84 data["fullname"] = data["fullname"].toLowerCase(); 85 var fullname = data["fullname"].trim().split(/\s+/).filter(Boolean).map((word) => { 86 return word[0].toUpperCase() + word.substring(1); 87 }); 88 var firstname = fullname.slice(0, -1).join(" "); 89 var lastname = fullname[fullname.length - 1]; 90 91 // get utm properties 92 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 93 94 // get contact 95 jQuery.ajax({ 96 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 97 type: 'POST', 98 contentType: 'application/json', 99 dataType: 'json', 100 data: JSON.stringify(dataGetContact), 101 success: function(resp) { 102 //console.log(resp); 103 var currentActionList = ''; 104 if (!resp['status'] && resp['status'] !== 'error') { 105 // have contact 106 // update properties into this contact 107 if (resp['properties']['non_signup_actions']) { 108 // already have properties 109 currentActionList = resp['properties']['non_signup_actions']['value']; 110 } 111 112 // already check content_download_report_2022 113 var newActionList = (currentActionList.indexOf("content_download_report_2022") == -1) ? currentActionList + ';content_download_report_2022' : currentActionList; 114 115 // don't update leadsource again 116 var snippetLeadSource = ''; 117 if ((katalonHubspot.isOverridableLeadsource(resp['properties'], 'Report 2022 Campaign Inbound')) && data["contact_experts"] == 'yes') { 118 // inbound team 119 snippetLeadSource = data["contact_experts"] == 'yes' ? `,\n"leadsource": "Report 2022 Campaign Inbound"` : ''; 120 //dataSendToHubspot.properties.leadsource = "Report 2022 Campaign Inbound"; 121 } 122 123 var dataSendToHubspot = `{ 124 "email": "${data["email"]}", 125 "properties": { 126 "firstname": "${firstname}", 127 "lastname": "${lastname}", 128 "jobtitle": "${data["job_title"]}", 129 "number_of_tester": "${data["number_of_tester"]}", 130 "current_testing_challenges": "${data["challenges"]}", 131 "book_a_demo": "${data["contact_experts"]}", 132 "self_reported_attribution": "${data["self_reported_attribution"]}", 133 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 134 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 135 "non_signup_actions": "${newActionList}" 136 ${snippetLeadSource} 137 ${snippetUtm} 138 } 139 }`; 140 141 //console.log(dataSendToHubspot); 142 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 143 144 // send for cold 145 // action after cold 146 let currentActionColdList = ''; 147 if (resp['properties']['website_actions_after_cold']) { 148 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 149 } 150 let newActionColdList = (currentActionColdList.indexOf("content_download_report_2022") == -1) ? currentActionColdList + `;content_download_report_2022` : currentActionColdList; 151 let coldActionData = ''; 152 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 153 // call api update for cold lead only 154 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`;
155 let dataColdSendToHubspot = `{ 156 "email": "${data["email"]}", 157 "properties": { 158 ${coldActionData} 159 } 160 }`; 161 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 162 } 163 } else { 164 // contact not exist 165 // outbound team 166 var snippetLeadSource = data["contact_experts"] == 'yes' ? `,\n"leadsource": "Report 2022 Campaign Outbound"` : ''; 167 168 // create a new contact 169 var dataCreateContact = `{ 170 "email": "${data["email"]}", 171 "firstname": "${firstname}", 172 "lastname": "${lastname}", 173 "properties": { 174 "jobtitle": "${data["job_title"]}", 175 "number_of_tester": "${data["number_of_tester"]}", 176 "current_testing_challenges": "${data["challenges"]}", 177 "book_a_demo": "${data["contact_experts"]}", 178 "self_reported_attribution": "${data["self_reported_attribution"]}", 179 "non_signup_actions": "content_download_report_2022", 180 "registration_status": "Non-register", 181 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 182 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 183 "form_source": "Website" 184 ${snippetUtm} 185 ${snippetLeadSource} 186 } 187 }`; 188 189 jQuery.ajax({ 190 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 191 type: 'POST', 192 contentType: 'application/json', 193 data: dataCreateContact, 194 success: function(resp) { 195 if (callback && typeof(callback) == "function") { 196 callback(); 197 } 198 } 199 }); 200 } 201 202 } 203 }); 204 } 205 206 // function tracking user submit contact trial TC form 207 this.trackUserSubmitTrialTestCloudForm = function(data, callback) { 208 var dataGetContact = `{ 209 "email": "${data["email"]}" 210 }`; 211 212 // format first and last name 213 data["fullname"] = data["fullname"].toLowerCase(); 214 var fullname = data["fullname"].trim().split(/\s+/).filter(Boolean).map((word) => { 215 return word[0].toUpperCase() + word.substring(1); 216 }); 217 var firstname = fullname.slice(0, -1).join(" "); 218 var lastname = fullname[fullname.length - 1]; 219 220 // get utm properties 221 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 222 223 // get contact 224 jQuery.ajax({ 225 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 226 type: 'POST', 227 contentType: 'application/json', 228 dataType: 'json', 229 data: dataGetContact, 230 success: function(resp) { 231 //console.log(resp); 232 var currentActionList = ''; 233 if (!resp['status'] && resp['status'] !== 'error') { 234 // have contact 235 // update properties into this contact 236 if (resp['properties']['non_signup_actions']) { 237 // already have properties 238 currentActionList = resp['properties']['non_signup_actions']['value']; 239 } 240 241 // already check trial testcloud 242 var newActionList = (currentActionList.indexOf("testcloud_lp") == -1) ? currentActionList + ';testcloud_lp' : currentActionList; 243 244 var dataSendToHubspot = `{ 245 "email": "${data["email"]}", 246 "properties": { 247 "firstname": "${firstname}", 248 "lastname": "${lastname}", 249 "number_of_tester": "${data["number_of_tester"]}", 250 "current_testing_challenges": "${data["challenges"]}", 251 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 252 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 253 "non_signup_actions": "${newActionList}" 254 ${snippetUtm} 255 } 256 }`; 257 258 //console.log(dataSendToHubspot); 259 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 260 261 // send for cold 262 // action after cold 263 let currentActionColdList = ''; 264 if (resp['properties']['website_actions_after_cold']) { 265 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 266 } 267 let newActionColdList = (currentActionColdList.indexOf("testcloud_lp") == -1) ? currentActionColdList + ';testcloud_lp' : currentActionColdList; 268 let coldActionData = ''; 269 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 270 // call api update for cold lead only 271 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`;
272 let dataColdSendToHubspot = `{ 273 "email": "${data["email"]}", 274 "properties": { 275 ${coldActionData} 276 } 277 }`; 278 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 279 } 280 } else { 281 // contact not exist 282 // create a new contact 283 var dataCreateContact = `{ 284 "email": "${data["email"]}", 285 "firstname": "${firstname}", 286 "lastname": "${lastname}", 287 "properties": { 288 "number_of_tester": "${data["number_of_tester"]}", 289 "current_testing_challenges": "${data["challenges"]}", 290 "non_signup_actions": "testcloud_lp", 291 "registration_status": "Non-register", 292 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 293 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 294 "form_source": "Website" 295 ${snippetUtm} 296 } 297 }`; 298 299 jQuery.ajax({ 300 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 301 type: 'POST', 302 contentType: 'application/json', 303 data: dataCreateContact, 304 success: function(resp) { 305 if (callback && typeof(callback) == "function") { 306 callback(); 307 } 308 } 309 }); 310 } 311 312 } 313 }); 314 } 315 316 // function tracking user submit ebook download form 317 this.trackUserDownloadEbook = function(data, callback) { 318 var dataGetContact = `{ 319 "email": "${data["email"]}" 320 }`; 321 322 // format first and last name 323 data["fullname"] = data["fullname"].toLowerCase(); 324 var fullname = data["fullname"].trim().split(/\s+/).filter(Boolean).map((word) => { 325 return word[0].toUpperCase() + word.substring(1); 326 }); 327 var firstname = fullname.slice(0, -1).join(" "); 328 var lastname = fullname[fullname.length - 1]; 329 330 // get utm properties 331 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 332 333 // get contact 334 jQuery.ajax({ 335 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 336 type: 'POST', 337 contentType: 'application/json', 338 dataType: 'json', 339 data: dataGetContact, 340 success: function(resp) { 341 //console.log(resp); 342 var currentActionList = ''; 343 if (!resp['status'] && resp['status'] !== 'error') { 344 // have contact 345 // update properties into this contact 346 if (resp['properties']['non_signup_actions']) { 347 // already have properties 348 currentActionList = resp['properties']['non_signup_actions']['value']; 349 } 350 351 // already check KS for QA Lead 352 var newActionList = (currentActionList.indexOf(data['ebook_name']) == -1) ? currentActionList + `;${data['ebook_name']}` : currentActionList; 353 354 355 var dataSendToHubspot = `{ 356 "email": "${data["email"]}", 357 "properties": { 358 "firstname": "${firstname}", 359 "lastname": "${lastname}", 360 "jobtitle": "${data["job_title"]}", 361 "which_aspect_of_testing_mobile_apps_are_you_interested_in_the_most": "${data["which_aspect_of_testing_mobile_apps_are_you_interested_in_the_most"] || ""}", 362 "self_reported_attribution": "${data["self_reported_attribution"]}", 363 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 364 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 365 "non_signup_actions": "${newActionList}" 366 ${snippetUtm} 367 } 368 }`; 369 370 katalonHubspot.sendToHubspot(dataSendToHubspot, () => { 371 // send for cold 372 // action after cold 373 let currentActionColdList = ''; 374 if (resp['properties']['website_actions_after_cold']) { 375 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 376 } 377 let newActionColdList = (currentActionColdList.indexOf(data['ebook_name']) == -1) ? currentActionColdList + `;${data['ebook_name']}` : currentActionColdList; 378 let coldActionData = ''; 379 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 380 // call api update for cold lead only 381 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`;
382 let dataColdSendToHubspot = `{ 383 "email": "${data["email"]}", 384 "properties": { 385 ${coldActionData} 386 } 387 }`; 388 katalonHubspot.sendToHubspot(dataColdSendToHubspot, callback); 389 } 390 }); 391 } else { 392 // contact not exist 393 394 // create a new contact 395 var dataCreateContact = `{ 396 "email": "${data["email"]}", 397 "firstname": "${firstname}", 398 "lastname": "${lastname}", 399 "properties": { 400 "jobtitle": "${data["job_title"]}", 401 "which_aspect_of_testing_mobile_apps_are_you_interested_in_the_most": "${data["which_aspect_of_testing_mobile_apps_are_you_interested_in_the_most"] || ""}", 402 "non_signup_actions": "${data['ebook_name']}", 403 "self_reported_attribution": "${data["self_reported_attribution"]}", 404 "registration_status": "Non-register", 405 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 406 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 407 "form_source": "Website" 408 ${snippetUtm} 409 } 410 }`; 411 412 //console.log(dataCreateContact); 413 414 jQuery.ajax({ 415 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 416 type: 'POST', 417 contentType: 'application/json', 418 data: dataCreateContact, 419 success: function(resp) { 420 if (callback && typeof(callback) == "function") { 421 callback(); 422 } 423 } 424 }); 425 } 426 427 } 428 }); 429 } 430 431 // this function to update Hubspot and check already leadsource 432 this.sendToHubspotHaveCheckLeadSource = function(data, callback) { 433 var dataGetContact = `{ 434 "email": "${data["email"]}" 435 }`; 436 // get contact 437 jQuery.ajax({ 438 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 439 type: 'POST', 440 contentType: 'application/json', 441 dataType: 'json', 442 data: dataGetContact, 443 success: function(resp) { 444 if (!resp['status'] && resp['status'] !== 'error' && (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"]))) { 445 // update Sep 17 2023 446 // have contact and don't have leadsource or leadsource can be override 447 var dataSendToHubspot = `{ 448 "email": "${data["email"]}", 449 "properties": { 450 "number_of_tester": "${data["number_of_tester"]}", 451 "current_testing_challenges": "${data["challenges"]}", 452 "leadsource": "${data["leadsource"]}" 453 } 454 }`; 455 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 456 } else { 457 // don't have contact 458 // do nothing 459 } 460 461 if (callback && typeof(callback) == "function") { 462 callback(); 463 } 464 } 465 }); 466 } 467 468 // this function send to Hubspot when user register webinar 469 this.trackUserRegisterWebinar = function(data, callback) { 470 var dataGetContact = `{ 471 "email": "${data["email"]}" 472 }`; 473 474 const capitalizeFirstLetter = (string) => { 475 return string.charAt(0).toUpperCase() + string.slice(1); 476 } 477 478 // format first and last name 479 const fullName = data["fullname"].toLowerCase(); 480 const names = fullName.trim().split(/\s+/); 481 482 const firstname = capitalizeFirstLetter(names[0]); 483 const remainingNames = names.slice(1); 484
485 remainingNames.forEach((name, index) => remainingNames[index] = capitalizeFirstLetter(name)); 486 const lastname = remainingNames.join(" "); 487 488 // get utm properties 489 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 490 491 // get contact 492 jQuery.ajax({ 493 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 494 type: 'POST', 495 contentType: 'application/json', 496 dataType: 'json', 497 data: dataGetContact, 498 success: function(resp) { 499 //console.log(resp); 500 var currentActionList = ''; 501 var hasMultipleSessions = data["webinar_multi_vendor_summit_jan_2024"] ? `,"webinar_multi_vendor_summit_jan_2024": "${data["webinar_multi_vendor_summit_jan_2024"]}"` : ''; 502 var hasKataConnectID = data["kata_connect_user_id"] ? `,"kata_connect_user_id": "${data["kata_connect_user_id"]}"` : ''; 503 var hasKataConnectUserLocation = data["kata_connect_user_location"] ? `,"kata_connect_user_location": "${data["kata_connect_user_location"]}"` : ''; 504 505 var hasKataConnectHowDid = data["kata_connect_how_did_you_hear_us"] ? `,"kata_connect_how_did_you_hear_us": "${data["kata_connect_how_did_you_hear_us"]}"` : ''; 506 var hasKataConnectHowDidOther = data["kata_connect_how_did_you_hear_us_other"] ? `,"kata_connect_how_did_you_hear_us_other": "${data["kata_connect_how_did_you_hear_us_other"]}"` : ''; 507 508 if (!resp['status'] && resp['status'] !== 'error') { 509 // have contact 510 // update properties into this contact 511 if (resp['properties']['non_signup_actions']) { 512 // already have properties 513 currentActionList = resp['properties']['non_signup_actions']['value']; 514 } 515 516 // check new action 517 var newActionList = (currentActionList.indexOf(data['webinar_name']) == -1) ? currentActionList + `;${data['webinar_name']}` : currentActionList; 518 519 var dataSendToHubspot = `{ 520 "email": "${data["email"]}", 521 "properties": { 522 "firstname": "${firstname}", 523 "lastname": "${lastname}", 524 "jobtitle": "${data["jobtitle"]}", 525 "self_reported_attribution": "${data["self_reported_attribution"]}", 526 "company_name_input_by_user": "${data["company_name_input_by_user"] ?? ''}", 527 "specific_topic_to_discuss": "${data["specific_topic_to_discuss"] ?? ''}", 528 "number_of_tester": "${data["number_of_tester"]}", 529 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 530 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 531 "non_signup_actions": "${newActionList}" 532 ${hasKataConnectID} 533 ${hasKataConnectUserLocation} 534 ${hasKataConnectHowDid} 535 ${hasKataConnectHowDidOther} 536 ${hasMultipleSessions} 537 ${snippetUtm} 538 } 539 }`; 540 541 //console.log(dataSendToHubspot); 542 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 543 544 // send for cold 545 // action after cold 546 let currentActionColdList = ''; 547 if (resp['properties']['website_actions_after_cold']) { 548 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 549 } 550 let newActionColdList = (currentActionColdList.indexOf(data['webinar_name']) == -1) ? currentActionColdList + `;${data['webinar_name']}` : currentActionColdList; 551 let coldActionData = ''; 552 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 553 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`;
554 let dataColdSendToHubspot = `{ 555 "email": "${data["email"]}", 556 "properties": { 557 ${coldActionData} 558 } 559 }`; 560 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 561 } 562 } else { 563 // contact not exisit 564 // create a new contact 565 var dataCreateContact = `{ 566 "email": "${data["email"]}", 567 "firstname": "${firstname}", 568 "lastname": "${lastname}", 569 "properties": { 570 "jobtitle": "${data["jobtitle"]}", 571 "number_of_tester": "${data["number_of_tester"]}", 572 "non_signup_actions": "${data['webinar_name']}", 573 "self_reported_attribution": "${data["self_reported_attribution"]}", 574 "company_name_input_by_user": "${data["company_name_input_by_user"] ?? ''}", 575 "specific_topic_to_discuss": "${data["specific_topic_to_discuss"] ?? ''}", 576 "registration_status": "Non-register", 577 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 578 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 579 "form_source": "Website" 580 ${hasKataConnectID} 581 ${hasKataConnectUserLocation} 582 ${hasKataConnectHowDid} 583 ${hasKataConnectHowDidOther} 584 ${hasMultipleSessions} 585 ${snippetUtm} 586 } 587 }`; 588 589 //console.log(dataCreateContact); 590 591 jQuery.ajax({ 592 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 593 type: 'POST', 594 contentType: 'application/json', 595 data: dataCreateContact, 596 success: function(resp) { 597 if (callback && typeof(callback) == "function") { 598 callback(); 599 } 600 } 601 }); 602 } 603 604 } 605 }); 606 } 607 608 // function submit SOQR2024 webinar 609 this.trackSubmitSOQR24Webinar = function(data, callback) { 610 var dataGetContact = `{ 611 "email": "${data["email"]}" 612 }`; 613 614 const capitalizeFirstLetter = (string) => { 615 return string.charAt(0).toUpperCase() + string.slice(1); 616 } 617 618 // format first and last name 619 const fullName = data["fullname"].toLowerCase(); 620 const names = fullName.trim().split(/\s+/); 621 622 const firstname = capitalizeFirstLetter(names[0]); 623 const remainingNames = names.slice(1); 624 625 remainingNames.forEach((name, index) => remainingNames[index] = capitalizeFirstLetter(name)); 626 const lastname = remainingNames.join(" "); 627 628 // get utm properties 629 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 630 631 // get contact 632 jQuery.ajax({ 633 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 634 type: 'POST', 635 contentType: 'application/json', 636 dataType: 'json', 637 data: dataGetContact, 638 success: function(resp) { 639 //console.log(resp); 640 var currentActionList = ''; 641 642 if (!resp['status'] && resp['status'] !== 'error') { 643 // have contact 644 // update properties into this contact 645 if (resp['properties']['non_signup_actions']) { 646 // already have properties 647 currentActionList = resp['properties']['non_signup_actions']['value']; 648 } 649 650 // check new action 651 var newActionList = (currentActionList.indexOf(data['webinar_name']) == -1) ? currentActionList + `;${data['webinar_name']}` : currentActionList; 652 653 var dataSendToHubspot = `{ 654 "email": "${data["email"]}", 655 "properties": { 656 "firstname": "${firstname}", 657 "lastname": "${lastname}", 658 "jobtitle": "${data["jobtitle"]}", 659 "which_stage_of_test_automation_best_describes_your_current_progress_": "${data["which_stage_of_test_automation_best_describes_your_current_progress_"]}", 660 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 661 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 662 "non_signup_actions": "${newActionList}" 663 ${snippetUtm} 664 } 665 }`; 666 667 //console.log(dataSendToHubspot); 668 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 669 670 // send for cold 671 // action after cold 672 let currentActionColdList = ''; 673 if (resp['properties']['website_actions_after_cold']) { 674 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 675 } 676 let newActionColdList = (currentActionColdList.indexOf(data['webinar_name']) == -1) ? currentActionColdList + `;${data['webinar_name']}` : currentActionColdList; 677 let coldActionData = ''; 678 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 679 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`;
680 let dataColdSendToHubspot = `{ 681 "email": "${data["email"]}", 682 "properties": { 683 ${coldActionData} 684 } 685 }`; 686 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 687 } 688 } else { 689 // contact not exisit 690 // create a new contact 691 var dataCreateContact = `{ 692 "email": "${data["email"]}", 693 "firstname": "${firstname}", 694 "lastname": "${lastname}", 695 "properties": { 696 "jobtitle": "${data["jobtitle"]}", 697 "non_signup_actions": "${data['webinar_name']}", 698 "which_stage_of_test_automation_best_describes_your_current_progress_": "${data["which_stage_of_test_automation_best_describes_your_current_progress_"]}", 699 "registration_status": "Non-register", 700 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 701 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 702 "form_source": "Website" 703 ${snippetUtm} 704 } 705 }`; 706 707 //console.log(dataCreateContact); 708 709 jQuery.ajax({ 710 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 711 type: 'POST', 712 contentType: 'application/json', 713 data: dataCreateContact, 714 success: function(resp) { 715 if (callback && typeof(callback) == "function") { 716 callback(); 717 } 718 } 719 }); 720 } 721 722 } 723 }); 724 } 725 726 // this function send to Hubspot when user register london event 727 this.trackUserRegisterLondonWebinar = function(data, callback) { 728 var dataGetContact = `{ 729 "email": "${data["email"]}" 730 }`; 731 732 const capitalizeFirstLetter = (string) => { 733 return string.charAt(0).toUpperCase() + string.slice(1); 734 } 735 736 // format first and last name 737 const fullName = data["fullname"].toLowerCase(); 738 const names = fullName.trim().split(/\s+/); 739 740 const firstname = capitalizeFirstLetter(names[0]); 741 const remainingNames = names.slice(1); 742 743 remainingNames.forEach((name, index) => remainingNames[index] = capitalizeFirstLetter(name)); 744 const lastname = remainingNames.join(" "); 745 746 // get utm properties 747 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 748 749 // get contact 750 jQuery.ajax({ 751 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 752 type: 'POST', 753 contentType: 'application/json', 754 dataType: 'json', 755 data: dataGetContact, 756 success: function(resp) { 757 //console.log(resp); 758 var currentActionList = ''; 759 if (!resp['status'] && resp['status'] !== 'error') { 760 // have contact 761 // update properties into this contact 762 if (resp['properties']['non_signup_actions']) { 763 // already have properties 764 currentActionList = resp['properties']['non_signup_actions']['value']; 765 } 766 767 // already check KS for QA Lead 768 var newActionList = (currentActionList.indexOf(data['webinar_name']) == -1) ? currentActionList + `;${data['webinar_name']}` : currentActionList; 769 770 771 var dataSendToHubspot = `{ 772 "email": "${data["email"]}", 773 "properties": { 774 "firstname": "${firstname}", 775 "lastname": "${lastname}", 776 "jobtitle": "${data["jobtitle"]}",
777 "london_event_company_name": "${data["london_event_company_name"]}", 778 "self_reported_attribution": "${data["self_reported_attribution"]}", 779 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 780 "specific_topic_to_discuss": "${data["specific_topic_to_discuss"] ?? ''}", 781 "number_of_tester": "${data["number_of_tester"]}", 782 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 783 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 784 "non_signup_actions": "${newActionList}" 785 ${snippetUtm} 786 } 787 }`; 788 789 //console.log(dataSendToHubspot); 790 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 791 792 // send for cold 793 // action after cold 794 let currentActionColdList = ''; 795 if (resp['properties']['website_actions_after_cold']) { 796 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 797 } 798 let newActionColdList = (currentActionColdList.indexOf(data['webinar_name']) == -1) ? currentActionColdList + `;${data['webinar_name']}` : currentActionColdList; 799 let coldActionData = ''; 800 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 801 // call api update for cold lead only 802 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`; 803 let dataColdSendToHubspot = `{ 804 "email": "${data["email"]}", 805 "properties": { 806 ${coldActionData} 807 } 808 }`; 809 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 810 } 811 812 } else { 813 // contact not exisit 814 // create a new contact 815 var dataCreateContact = `{ 816 "email": "${data["email"]}", 817 "firstname": "${firstname}", 818 "lastname": "${lastname}", 819 "properties": { 820 "jobtitle": "${data["jobtitle"]}", 821 "number_of_tester": "${data["number_of_tester"]}", 822 "london_event_company_name": "${data["london_event_company_name"]}", 823 "non_signup_actions": "${data['webinar_name']}", 824 "self_reported_attribution": "${data["self_reported_attribution"]}", 825 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 826 "specific_topic_to_discuss": "${data["specific_topic_to_discuss"] ?? ''}", 827 "registration_status": "Non-register", 828 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 829 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 830 "form_source": "Website" 831 ${snippetUtm} 832 } 833 }`; 834 835 //console.log(dataCreateContact); 836 837 jQuery.ajax({ 838 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 839 type: 'POST', 840 contentType: 'application/json', 841 data: dataCreateContact, 842 success: function(resp) { 843 if (callback && typeof(callback) == "function") { 844 callback(); 845 } 846 } 847 }); 848 } 849 850 } 851 }); 852 } 853 854 // this function send to Hubspot when user register custom event 855 this.trackUserRegisterCustomWebinar = function(data, callback) { 856 var dataGetContact = `{ 857 "email": "${data["email"]}" 858 }`; 859 860 const capitalizeFirstLetter = (string) => { 861 return string.charAt(0).toUpperCase() + string.slice(1); 862 } 863 864 // format first and last name 865 const fullName = data["fullname"].toLowerCase(); 866 const names = fullName.trim().split(/\s+/); 867 868 const firstname = capitalizeFirstLetter(names[0]); 869 const remainingNames = names.slice(1); 870
871 remainingNames.forEach((name, index) => remainingNames[index] = capitalizeFirstLetter(name)); 872 const lastname = remainingNames.join(" "); 873 874 // get utm properties 875 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 876 877 // get contact 878 jQuery.ajax({ 879 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 880 type: 'POST', 881 contentType: 'application/json', 882 dataType: 'json', 883 data: dataGetContact, 884 success: function(resp) { 885 //console.log(resp); 886 var currentActionList = ''; 887 if (!resp['status'] && resp['status'] !== 'error') { 888 // have contact 889 // update properties into this contact 890 if (resp['properties']['non_signup_actions']) { 891 // already have properties 892 currentActionList = resp['properties']['non_signup_actions']['value']; 893 } 894 895 // already check KS for QA Lead 896 var newActionList = (currentActionList.indexOf(data['webinar_name']) == -1) ? currentActionList + `;${data['webinar_name']}` : currentActionList; 897 898 899 var dataSendToHubspot = `{ 900 "email": "${data["email"]}", 901 "properties": { 902 "firstname": "${firstname}", 903 "lastname": "${lastname}", 904 "jobtitle": "${data["jobtitle"]}", 905 "london_event_company_name": "${data["london_event_company_name"]}", 906 "self_reported_attribution": "${data["self_reported_attribution"]}", 907 "number_of_tester": "${data["number_of_tester"]}", 908 "user_objective": "${data["user_objective"]}", 909 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 910 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 911 "non_signup_actions": "${newActionList}" 912 ${snippetUtm} 913 } 914 }`; 915 916 //console.log(dataSendToHubspot); 917 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 918 919 // send for cold 920 // action after cold 921 let currentActionColdList = ''; 922 if (resp['properties']['website_actions_after_cold']) { 923 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 924 } 925 let newActionColdList = (currentActionColdList.indexOf(data['webinar_name']) == -1) ? currentActionColdList + `;${data['webinar_name']}` : currentActionColdList; 926 let coldActionData = ''; 927 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 928 // call api update for cold lead only 929 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`; 930 let dataColdSendToHubspot = `{ 931 "email": "${data["email"]}", 932 "properties": { 933 ${coldActionData} 934 } 935 }`; 936 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 937 } 938 } else { 939 // contact not exisit 940 // create a new contact 941 var dataCreateContact = `{ 942 "email": "${data["email"]}", 943 "firstname": "${firstname}", 944 "lastname": "${lastname}", 945 "properties": { 946 "jobtitle": "${data["jobtitle"]}", 947 "number_of_tester": "${data["number_of_tester"]}",
948 "london_event_company_name": "${data["london_event_company_name"]}", 949 "non_signup_actions": "${data['webinar_name']}", 950 "self_reported_attribution": "${data["self_reported_attribution"]}", 951 "user_objective": "${data["user_objective"]}", 952 "registration_status": "Non-register", 953 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 954 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 955 "form_source": "Website" 956 ${snippetUtm} 957 } 958 }`; 959 960 //console.log(dataCreateContact); 961 962 jQuery.ajax({ 963 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 964 type: 'POST', 965 contentType: 'application/json', 966 data: dataCreateContact, 967 success: function(resp) { 968 if (callback && typeof(callback) == "function") { 969 callback(); 970 } 971 } 972 }); 973 } 974 975 } 976 }); 977 } 978 979 // this function send to Hubspot when user register post webinar 980 this.trackUserRegisterPostWebinar = function(data, callback) { 981 var dataGetContact = `{ 982 "email": "${data["email"]}" 983 }`; 984 985 const capitalizeFirstLetter = (string) => { 986 return string.charAt(0).toUpperCase() + string.slice(1); 987 } 988 989 // format first and last name 990 const fullName = data["fullname"].toLowerCase(); 991 const names = fullName.trim().split(/\s+/); 992 993 const firstname = capitalizeFirstLetter(names[0]); 994 const remainingNames = names.slice(1); 995 996 remainingNames.forEach((name, index) => remainingNames[index] = capitalizeFirstLetter(name)); 997 const lastname = remainingNames.join(" "); 998 999 // get utm properties 1000 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 1001 1002 // get contact 1003 jQuery.ajax({ 1004 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 1005 type: 'POST', 1006 contentType: 'application/json', 1007 dataType: 'json', 1008 data: dataGetContact, 1009 success: function(resp) { 1010 //console.log(resp); 1011 var currentActionList = ''; 1012 if (!resp['status'] && resp['status'] !== 'error') { 1013 // have contact 1014 // update properties into this contact 1015 if (resp['properties']['non_signup_actions']) { 1016 // already have properties 1017 currentActionList = resp['properties']['non_signup_actions']['value']; 1018 } 1019 1020 // already check KS for QA Lead 1021 var newActionList = (currentActionList.indexOf(data['webinar_name']) == -1) ? currentActionList + `;${data['webinar_name']}` : currentActionList; 1022 1023 1024 var dataSendToHubspot = `{ 1025 "email": "${data["email"]}", 1026 "properties": { 1027 "firstname": "${firstname}", 1028 "lastname": "${lastname}", 1029 "jobtitle": "${data["jobtitle"]}", 1030 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1031 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1032 "non_signup_actions": "${newActionList}" 1033 ${snippetUtm} 1034 } 1035 }`; 1036 1037 //console.log(dataSendToHubspot); 1038 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 1039 1040 // send for cold 1041 // action after cold 1042 let currentActionColdList = ''; 1043 if (resp['properties']['website_actions_after_cold']) { 1044 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 1045 } 1046 let newActionColdList = (currentActionColdList.indexOf(data['webinar_name']) == -1) ? currentActionColdList + `;${data['webinar_name']}` : currentActionColdList; 1047 let coldActionData = ''; 1048 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 1049 // call api update for cold lead only 1050 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`;
1051 let dataColdSendToHubspot = `{ 1052 "email": "${data["email"]}", 1053 "properties": { 1054 ${coldActionData} 1055 } 1056 }`; 1057 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 1058 } 1059 } else { 1060 // contact not exisit 1061 // create a new contact 1062 var dataCreateContact = `{ 1063 "email": "${data["email"]}", 1064 "firstname": "${firstname}", 1065 "lastname": "${lastname}", 1066 "properties": { 1067 "jobtitle": "${data["jobtitle"]}", 1068 "non_signup_actions": "${data['webinar_name']}", 1069 "registration_status": "Non-register", 1070 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1071 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1072 "form_source": "Website" 1073 ${snippetUtm} 1074 } 1075 }`; 1076 1077 //console.log(dataCreateContact); 1078 1079 jQuery.ajax({ 1080 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 1081 type: 'POST', 1082 contentType: 'application/json', 1083 data: dataCreateContact, 1084 success: function(resp) { 1085 if (callback && typeof(callback) == "function") { 1086 callback(); 1087 } 1088 } 1089 }); 1090 } 1091 1092 } 1093 }); 1094 } 1095 1096 // this fucntion send to Hubspot when user submit view a demo form 1097 this.trackSubmitViewADemoForm = function(data, callback) { 1098 var dataGetContact = `{ 1099 "email": "${data["email"]}" 1100 }`; 1101 1102 // format first and last name 1103 const fullname = []; 1104 1105 data["fullname"].toLowerCase().trim().split(/\s+/).filter(Boolean).map((word) => { 1106 fullname.push(word[0].toUpperCase() + word.substring(1)); 1107 }); 1108 1109 let firstname = ""; 1110 let lastname = ""; 1111 1112 fullname.map((name, index) => { 1113 if (index === 0) { 1114 firstname = name; 1115 } 1116 else if (index + 1 === fullname.length) { 1117 lastname += name; 1118 } 1119 else { 1120 lastname += name + " "; 1121 } 1122 }); 1123 1124 // get time now 1125 var timeSubmit = Date.now(); 1126 1127 // get utm properties 1128 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 1129 1130 // get contact 1131 jQuery.ajax({ 1132 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 1133 type: 'POST', 1134 contentType: 'application/json', 1135 dataType: 'json', 1136 data: dataGetContact, 1137 success: function(resp) { 1138 if (!resp['status'] && resp['status'] !== 'error') { 1139 // have contact 1140 if (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"])) { 1141 // update Sep 17 2023 1142 // don't have leadsource or leadsource can be override 1143 var dataSendToHubspot = `{ 1144 "email": "${data["email"]}", 1145 "properties": { 1146 "firstname": "${firstname}", 1147 "lastname": "${lastname}", 1148 "number_of_tester": "${data["number_of_tester"] ?? ''}", 1149 "current_testing_challenges": "${data["challenges"] ?? ''}", 1150 "current_testing_challenges_detail": "${data["current_testing_challenges_detail"] ?? ''}", 1151 "self_reported_attribution": "${data["self_reported_attribution"] ?? ''}", 1152 "self_reported_attribution_detail": "${data["self_reported_attribution_detail"] ?? ''}", 1153 "jobtitle": "${data["jobtitle"]}", 1154 "custom_company_country": "${data["custom_company_country"] ?? ''}", 1155 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 1156 "leadsource": "${data["leadsource"]}", 1157 "leadsource_by_campaign": "${data["leadsource_by_campaign"] ?? 'Others'}", 1158 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1159 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1160 "last_time_submit": "${timeSubmit}" 1161 ${snippetUtm} 1162 } 1163 }`; 1164 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 1165 } 1166 1167 // update leadsource 2nd for cold 1168 if (katalonHubspot.isOverridableLeadsourceForCold(resp['properties'], data["leadsource"])) {
1169 let dataColdSendToHubspot = `{ 1170 "email": "${data["email"]}", 1171 "properties": { 1172 "firstname": "${firstname}", 1173 "lastname": "${lastname}", 1174 "number_of_tester": "${data["number_of_tester"] ?? ''}", 1175 "current_testing_challenges": "${data["challenges"] ?? ''}", 1176 "current_testing_challenges_detail": "${data["current_testing_challenges_detail"] ?? ''}", 1177 "self_reported_attribution": "${data["self_reported_attribution"] ?? ''}", 1178 "self_reported_attribution_detail": "${data["self_reported_attribution_detail"] ?? ''}", 1179 "jobtitle": "${data["jobtitle"]}", 1180 "custom_company_country": "${data["custom_company_country"] ?? ''}", 1181 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 1182 "leadsource_2nd": "${data["leadsource"]}", 1183 "leadsource_by_campaign_2nd": "${data["leadsource_by_campaign"] ?? 'Others'}", 1184 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1185 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1186 "last_time_cold_submit": "${timeSubmit}" 1187 ${snippetUtm} 1188 } 1189 }`; 1190 katalonHubspot.sendToHubspot(dataColdSendToHubspot, callback); 1191 } 1192 } else { 1193 // don't have contact 1194 // create new contact with leadsource 1195 var dataCreateContact = `{ 1196 "email": "${data["email"]}", 1197 "firstname": "${firstname}", 1198 "lastname": "${lastname}", 1199 "properties": { 1200 "number_of_tester": "${data["number_of_tester"] ?? ''}", 1201 "current_testing_challenges": "${data["challenges"] ?? ''}", 1202 "current_testing_challenges_detail": "${data["current_testing_challenges_detail"] ?? ''}", 1203 "self_reported_attribution": "${data["self_reported_attribution"] ?? ''}", 1204 "self_reported_attribution_detail": "${data["self_reported_attribution_detail"] ?? ''}", 1205 "jobtitle": "${data["jobtitle"]}", 1206 "custom_company_country": "${data["custom_company_country"] ?? ''}", 1207 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 1208 "registration_status": "Non-register", 1209 "form_source": "Website", 1210 "leadsource": "${data["leadsource"]}", 1211 "leadsource_by_campaign": "${data["leadsource_by_campaign"] ?? 'Others'}", 1212 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1213 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1214 "last_time_submit": "${timeSubmit}" 1215 ${snippetUtm} 1216 } 1217 }`; 1218 1219 jQuery.ajax({ 1220 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 1221 type: 'POST', 1222 contentType: 'application/json', 1223 data: dataCreateContact, 1224 success: function(resp) { 1225 if (callback && typeof(callback) == "function") { 1226 callback(); 1227 } 1228 } 1229 }); 1230 } 1231 1232 } 1233 }); 1234 } 1235 1236 // this function log a failed HubSpot relay call so a lost contact sync is visible instead of silent
1237 this.reportContactSyncError = function(endpoint, email, formName, detail) { 1238 console.error(`[KatalonHubspot] ${formName}: ${endpoint} failed for ${email}`, detail); 1239 1240 if (typeof analytics !== 'undefined' && typeof katalonTracking !== 'undefined') { 1241 katalonTracking.track('HubSpot Contact Sync Failed', { 1242 email_user: email, 1243 endpoint: endpoint, 1244 form_name: formName, 1245 error_detail: String(detail && detail.message ? detail.message : detail), 1246 source_url: window.location.href 1247 }, { 1248 category: 'Sales related action', 1249 label: formName 1250 }); 1251 } 1252 } 1253 1254 // this fucntion send to Hubspot when user submit contact us form 1255 this.trackSubmitContactUsForm = function(data, callback) { 1256 const formName = 'Contact Us Form'; 1257 1258 // POST to the WordPress HubSpot relay; build the body with JSON.stringify so free-text 1259 // answers containing quotes, backslashes or newlines can't produce an invalid payload 1260 const postContactApi = (endpoint, payload, onSuccess) => { 1261 jQuery.ajax({ 1262 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/' + endpoint, 1263 type: 'POST', 1264 contentType: 'application/json', 1265 // create-contact doesn't reliably answer with JSON, so only parse the lookup/update responses 1266 dataType: endpoint === 'create-contact' ? undefined : 'json', 1267 data: JSON.stringify(payload), 1268 success: onSuccess, 1269 error: function(xhr, textStatus, errorThrown) { 1270 katalonHubspot.reportContactSyncError(endpoint, data["email"], formName, `${xhr.status} ${textStatus} ${errorThrown || ''}`.trim()); 1271 } 1272 }); 1273 }; 1274 1275 // drop missing values instead of sending "undefined"/"null" strings, keep everything else as a string like before 1276 const toContactProperties = (properties) => Object.keys(properties).reduce((result, key) => { 1277 if (properties[key] !== undefined && properties[key] !== null) { 1278 result[key] = `${properties[key]}`; 1279 } 1280 return result; 1281 }, {}); 1282 1283 const runCallback = () => { 1284 if (callback && typeof(callback) == "function") { 1285 callback(); 1286 } 1287 }; 1288 1289 try { 1290 // format first and last name 1291 const fullname = String(data["fullname"] ?? '').toLowerCase().trim().split(/\s+/).filter(Boolean) 1292 .map((word) => word[0].toUpperCase() + word.substring(1)); 1293 const firstname = fullname[0] || ''; 1294 const lastname = fullname.slice(1).join(' '); 1295 1296 // get time now 1297 const timeSubmit = Date.now(); 1298 1299 // get utm properties 1300 const utmProperties = katalonHubspot.getUtmAndAdsClickProperties(); 1301 1302 const formProperties = toContactProperties({ 1303 number_of_tester: data["number_of_tester"], 1304 current_testing_challenges: data["challenges"], 1305 current_testing_challenges_detail: data["current_testing_challenges_detail"] ?? '', 1306 self_reported_attribution: data["self_reported_attribution"], 1307 self_reported_attribution_detail: data["self_reported_attribution_detail"] ?? '', 1308 jobtitle: data["jobtitle"] ?? '', 1309 custom_company_country: data["custom_company_country"] ?? '', 1310 custom_phone_number: data["custom_phone_number"] ?? '', 1311 usebouncer_email_status: data["usebouncer_email_status"], 1312 usebouncer_domain_type: data["usebouncer_domain_type"] 1313 }); 1314 1315 // get contact 1316 postContactApi('get-contact', { email: data["email"] }, function(resp) { 1317 if (!resp['status'] && resp['status'] !== 'error') { 1318 // have contact 1319 if (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"])) { 1320 // update Sep 17 2023 1321 // don't have leadsource or leadsource can be override 1322 postContactApi('update-contact', { 1323 email: data["email"], 1324 properties: { 1325 firstname, 1326 lastname, 1327 ...formProperties, 1328 leadsource: data["leadsource"], 1329 leadsource_by_campaign: data["leadsource_by_campaign"], 1330 last_time_submit: `${timeSubmit}`, 1331 ...utmProperties 1332 } 1333 }, runCallback); 1334 } 1335 1336 // update leadsource 2nd for cold 1337 if (katalonHubspot.isOverridableLeadsourceForCold(resp['properties'], data["leadsource"])) { 1338 postContactApi('update-contact', { 1339 email: data["email"], 1340 properties: { 1341 firstname, 1342 lastname, 1343 ...formProperties, 1344 leadsource_2nd: data["leadsource"], 1345 leadsource_by_campaign_2nd: data["leadsource_by_campaign"], 1346 last_time_cold_submit: `${timeSubmit}`, 1347 ...utmProperties 1348 } 1349 }, runCallback); 1350 } 1351 } else { 1352 // don't have contact 1353 // create new contact with leadsource 1354 postContactApi('create-contact', { 1355 email: data["email"], 1356 firstname, 1357 lastname, 1358 properties: { 1359 ...formProperties, 1360 registration_status: 'Non-register', 1361 form_source: 'Website', 1362 leadsource: data["leadsource"], 1363 leadsource_by_campaign: data["leadsource_by_campaign"], 1364 last_time_submit: `${timeSubmit}`, 1365 ...utmProperties 1366 } 1367 }, runCallback); 1368 } 1369 }); 1370 } catch (e) { 1371 katalonHubspot.reportContactSyncError('get-contact', data && data["email"], formName, e); 1372 } 1373 } 1374 1375 // this fucntion send to Hubspot when user submit book call form 1376 this.trackSubmitBookCallForm = function(data, callback) { 1377 var dataGetContact = `{ 1378 "email": "${data["email"]}" 1379 }`; 1380 1381 // format first and last name 1382 const fullname = []; 1383 1384 data["fullname"].toLowerCase().trim().split(/\s+/).filter(
1384Boolean).map((word) => { 1385 fullname.push(word[0].toUpperCase() + word.substring(1)); 1386 }); 1387 1388 let firstname = ""; 1389 let lastname = ""; 1390 1391 fullname.map((name, index) => { 1392 if (index === 0) { 1393 firstname = name; 1394 } 1395 else if (index + 1 === fullname.length) { 1396 lastname += name; 1397 } 1398 else { 1399 lastname += name + " "; 1400 } 1401 }); 1402 1403 // get time now 1404 var timeSubmit = Date.now(); 1405 1406 // get utm properties 1407 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 1408 1409 // get contact 1410 jQuery.ajax({ 1411 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 1412 type: 'POST', 1413 contentType: 'application/json', 1414 dataType: 'json', 1415 data: dataGetContact, 1416 success: function(resp) { 1417 if (!resp['status'] && resp['status'] !== 'error') { 1418 // have contact 1419 if (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"])) { 1420 // update Sep 17 2023 1421 // don't have leadsource or leadsource can be override 1422 var dataSendToHubspot = `{ 1423 "email": "${data["email"]}", 1424 "properties": { 1425 "firstname": "${firstname}", 1426 "lastname": "${lastname}", 1427 "number_of_tester": "${data["number_of_tester"]}", 1428 "current_testing_challenges": "${data["challenges"]}", 1429 "self_reported_attribution": "${data["self_reported_attribution"]}", 1430 "custom_company_country": "${data["custom_company_country"] ?? ''}", 1431 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 1432 "leadsource": "${data["leadsource"]}", 1433 "leadsource_by_campaign": "${data["leadsource_by_campaign"]}", 1434 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1435 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1436 "last_time_submit": "${timeSubmit}" 1437 ${snippetUtm} 1438 } 1439 }`; 1440 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 1441 } 1442 1443 // update leadsource 2nd for cold 1444 if (katalonHubspot.isOverridableLeadsourceForCold(resp['properties'], data["leadsource"])) { 1445 let dataColdSendToHubspot = `{ 1446 "email": "${data["email"]}", 1447 "properties": { 1448 "firstname": "${firstname}", 1449 "lastname": "${lastname}", 1450 "number_of_tester": "${data["number_of_tester"]}", 1451 "current_testing_challenges": "${data["challenges"]}", 1452 "self_reported_attribution": "${data["self_reported_attribution"]}", 1453 "custom_company_country": "${data["custom_company_country"] ?? ''}", 1454 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 1455 "leadsource_2nd": "${data["leadsource"]}", 1456 "leadsource_by_campaign_2nd": "${data["leadsource_by_campaign"]}", 1457 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1458 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1459 "last_time_cold_submit": "${timeSubmit}" 1460 ${snippetUtm} 1461 } 1462 }`; 1463 katalonHubspot.sendToHubspot(dataColdSendTo
1463Hubspot, callback); 1464 } 1465 } else { 1466 // don't have contact 1467 // create new contact with leadsource 1468 var dataCreateContact = `{ 1469 "email": "${data["email"]}", 1470 "firstname": "${firstname}", 1471 "lastname": "${lastname}", 1472 "properties": { 1473 "number_of_tester": "${data["number_of_tester"]}", 1474 "current_testing_challenges": "${data["challenges"]}", 1475 "self_reported_attribution": "${data["self_reported_attribution"]}", 1476 "custom_company_country": "${data["custom_company_country"] ?? ''}", 1477 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 1478 "registration_status": "Non-register", 1479 "form_source": "Website", 1480 "leadsource": "${data["leadsource"]}", 1481 "leadsource_by_campaign": "${data["leadsource_by_campaign"]}", 1482 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1483 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1484 "last_time_submit": "${timeSubmit}" 1485 ${snippetUtm} 1486 } 1487 }`; 1488 1489 jQuery.ajax({ 1490 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 1491 type: 'POST', 1492 contentType: 'application/json', 1493 data: dataCreateContact, 1494 success: function(resp) { 1495 if (callback && typeof(callback) == "function") { 1496 callback(); 1497 } 1498 } 1499 }); 1500 } 1501 1502 } 1503 }); 1504 } 1505 1506 // this fucntion send to Hubspot when user submit book call form for Dreamforce 1507 this.trackSubmitDreamforceBookCallForm = function(data, callback) { 1508 var dataGetContact = `{ 1509 "email": "${data["email"]}" 1510 }`; 1511 1512 // format first and last name 1513 const fullname = []; 1514 1515 data["fullname"].toLowerCase().trim().split(/\s+/).filter(Boolean).map((word) => { 1516 fullname.push(word[0].toUpperCase() + word.substring(1)); 1517 }); 1518 1519 let firstname = ""; 1520 let lastname = ""; 1521 1522 fullname.map((name, index) => { 1523 if (index === 0) { 1524 firstname = name; 1525 } 1526 else if (index + 1 === fullname.length) { 1527 lastname += name; 1528 } 1529 else { 1530 lastname += name + " "; 1531 } 1532 }); 1533 1534 // get time now 1535 var timeSubmit = Date.now(); 1536 1537 // get utm properties 1538 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 1539 1540 // get contact 1541 jQuery.ajax({ 1542 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 1543 type: 'POST', 1544 contentType: 'application/json', 1545 dataType: 'json', 1546 data: dataGetContact, 1547 success: function(resp) { 1548 if (!resp['status'] && resp['status'] !== 'error') { 1549 // have contact 1550 if (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"])) { 1551 // update Sep 17 2023 1552 // don't have leadsource or leadsource can be override 1553 var dataSendToHubspot = `{ 1554 "email": "${data["email"]}", 1555 "properties": { 1556 "firstname": "${firstname}", 1557 "lastname": "${lastname}", 1558 "company_name_input_by_user": "${data["company_name_input_by_user"]}", 1559 "leadsource": "${data["leadsource"]}", 1560 "leadsource_by_campaign": "${data["leadsource_by_campaign"]}", 1561 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1562 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1563 "last_time_submit": "${timeSubmit}" 1564 ${snippetUtm} 1565 } 1566 }`; 1567 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 1568 } else { 1569 // have leadsource -> don't override it 1570 } 1571 } else { 1572 // don't have contact 1573 // create new contact with leadsource 1574 var dataCreateContact = `{ 1575 "email": "${data["email"]}", 1576 "firstname": "${firstname}", 1577 "lastname": "${lastname}", 1578 "properties": { 1579 "company_name_input_by_user": "${data["company_name_input_by_user"]}", 1580 "registration_status": "Non-register", 1581 "form_source": "Website", 1582 "leadsource": "${data["leadsource"]}", 1583 "leadsource_by_campaign": "${data["leadsource_by_campaign"]}", 1584 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1585 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1586 "last_time_submit": "${timeSubmit}" 1587 ${snippetUtm} 1588 } 1589 }`; 1590 1591 jQuery.ajax({ 1592 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 1593 type: 'POST', 1594 contentType: 'application/json', 1595 data: dataCreateContact, 1596 success: function(resp) { 1597 if (callback && typeof(callback) == "function") { 1598 callback(); 1599 } 1600 } 1601 }); 1602 } 1603 1604 } 1605 }); 1606 } 1607 1608 // this fucntion send to Hubspot when user submit download whitepaper 2020 form 1609 this.submitDownloadWhitePaper2020 = function(data, callback) { 1610 var dataGetContact = `{ 1611 "email": "${data["email"]}" 1612 }`; 1613 1614 // format first and last name 1615 data["fullname"] = data["fullname"].toLowerCase(); 1616 var fullname = data["fullname"].trim().split(/\s+/).filter(
1616Boolean).map((word) => { 1617 return word[0].toUpperCase() + word.substring(1); 1618 }); 1619 var firstname = fullname.slice(0, -1).join(" "); 1620 var lastname = fullname[fullname.length - 1]; 1621 1622 // get utm properties 1623 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 1624 1625 // get contact 1626 jQuery.ajax({ 1627 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 1628 type: 'POST', 1629 contentType: 'application/json', 1630 dataType: 'json', 1631 data: dataGetContact, 1632 success: function(resp) { 1633 //console.log(resp); 1634 var currentActionList = ''; 1635 if (!resp['status'] && resp['status'] !== 'error') { 1636 // have contact 1637 // update properties into this contact 1638 if (resp['properties']['non_signup_actions']) { 1639 // already have properties 1640 currentActionList = resp['properties']['non_signup_actions']['value']; 1641 } 1642 1643 // already check KS for QA Lead 1644 var newActionList = (currentActionList.indexOf(data['whitepaper_name']) == -1) ? currentActionList + `;${data['whitepaper_name']}` : currentActionList; 1645 1646 1647 var dataSendToHubspot = `{ 1648 "email": "${data["email"]}", 1649 "properties": { 1650 "firstname": "${firstname}", 1651 "lastname": "${lastname}", 1652 "jobtitle": "${data["jobtitle"]}", 1653 "non_signup_actions": "${newActionList}" 1654 ${snippetUtm} 1655 } 1656 }`; 1657 1658 //console.log(dataSendToHubspot); 1659 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 1660 1661 // send for cold 1662 // action after cold 1663 let currentActionColdList = ''; 1664 if (resp['properties']['website_actions_after_cold']) { 1665 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 1666 } 1667 let newActionColdList = (currentActionColdList.indexOf(data['whitepaper_name']) == -1) ? currentActionColdList + `;${data['whitepaper_name']}` : currentActionColdList; 1668 let coldActionData = ''; 1669 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 1670 // call api update for cold lead only 1671 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`; 1672 let dataColdSendToHubspot = `{ 1673 "email": "${data["email"]}", 1674 "properties": { 1675 ${coldActionData} 1676 } 1677 }`; 1678 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 1679 } 1680 } else { 1681 // contact not exisit 1682 // create a new contact 1683 var dataCreateContact = `{ 1684 "email": "${data["email"]}", 1685 "firstname": "${firstname}", 1686 "lastname": "${lastname}", 1687 "properties": { 1688 "jobtitle": "${data["jobtitle"]}", 1689 "non_signup_actions": "${data['whitepaper_name']}", 1690 "registration_status": "Non-register", 1691 "form_source": "Website" 1692 ${snippetUtm} 1693 } 1694 }`; 1695 1696 //console.log(dataCreateContact); 1697 1698 jQuery.ajax({ 1699 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 1700 type: 'POST', 1701 contentType: 'application/json', 1702 data: dataCreateContact, 1703 success: function(resp) { 1704 if (callback && typeof(callback) == "function") { 1705 callback(); 1706 } 1707 } 1708 }); 1709 } 1710 1711 } 1712 }); 1713 } 1714 1715 // this fucntion send to Hubspot when user submit download whitepaper 2020 form 1716 this.submitDownloadWhitePaper2021 = function(data, callback) { 1717 var dataGetContact = `{ 1718 "email": "${data["email"]}" 1719 }`; 1720 1721 // format first and last name 1722 data["fullname"] = data["fullname"].toLowerCase(); 1723 var fullname = data["fullname"].trim().split(/\s+/).filter(
1723Boolean).map((word) => { 1724 return word[0].toUpperCase() + word.substring(1); 1725 }); 1726 var firstname = fullname.slice(0, -1).join(" "); 1727 var lastname = fullname[fullname.length - 1]; 1728 1729 // get utm properties 1730 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 1731 1732 // get contact 1733 jQuery.ajax({ 1734 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 1735 type: 'POST', 1736 contentType: 'application/json', 1737 dataType: 'json', 1738 data: dataGetContact, 1739 success: function(resp) { 1740 //console.log(resp); 1741 var currentActionList = ''; 1742 if (!resp['status'] && resp['status'] !== 'error') { 1743 // have contact 1744 // update properties into this contact 1745 if (resp['properties']['non_signup_actions']) { 1746 // already have properties 1747 currentActionList = resp['properties']['non_signup_actions']['value']; 1748 } 1749 1750 // already check KS for QA Lead 1751 var newActionList = (currentActionList.indexOf(data['whitepaper_name']) == -1) ? currentActionList + `;${data['whitepaper_name']}` : currentActionList; 1752 1753 1754 var dataSendToHubspot = `{ 1755 "email": "${data["email"]}", 1756 "properties": { 1757 "firstname": "${firstname}", 1758 "lastname": "${lastname}", 1759 "jobtitle": "${data["jobtitle"]}", 1760 "number_of_tester": "${data["number_of_tester"]}", 1761 "current_testing_challenges": "${data["challenges"]}", 1762 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1763 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1764 "non_signup_actions": "${newActionList}" 1765 ${snippetUtm} 1766 } 1767 }`; 1768 1769 //console.log(dataSendToHubspot); 1770 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 1771 1772 // send for cold 1773 // action after cold 1774 let currentActionColdList = ''; 1775 if (resp['properties']['website_actions_after_cold']) { 1776 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 1777 } 1778 let newActionColdList = (currentActionColdList.indexOf(data['whitepaper_name']) == -1) ? currentActionColdList + `;${data['whitepaper_name']}` : currentActionColdList; 1779 let coldActionData = ''; 1780 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 1781 // call api update for cold lead only 1782 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`; 1783 let dataColdSendToHubspot = `{ 1784 "email": "${data["email"]}", 1785 "properties": { 1786 ${coldActionData} 1787 } 1788 }`; 1789 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 1790 } 1791 } else { 1792 // contact not exisit 1793 // create a new contact 1794 var dataCreateContact = `{ 1795 "email": "${data["email"]}", 1796 "firstname": "${firstname}", 1797 "lastname": "${lastname}", 1798 "properties": { 1799 "jobtitle": "${data["jobtitle"]}", 1800 "number_of_tester": "${data["number_of_tester"]}", 1801 "current_testing_challenges": "${data["challenges"]}", 1802 "non_signup_actions": "${data['whitepaper_name']}", 1803 "registration_status": "Non-register", 1804 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1805 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1806 "form_source": "Website" 1807 ${snippetUtm} 1808 } 1809 }`; 1810 1811 //console.log(dataCreateContact); 1812 1813 jQuery.ajax({ 1814 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 1815 type: 'POST', 1816 contentType: 'application/json', 1817 data: dataCreateContact, 1818 success: function(resp) { 1819 if (callback && typeof(callback) == "function") { 1820 callback(); 1821 } 1822 } 1823 }); 1824 } 1825 1826 } 1827 }); 1828 } 1829 1830 // this fucntion send to Hubspot when user submit view a demo form 1831 this.trackSubmitWebinarAfterForm = function(data, callback) { 1832 var dataGetContact = `{ 1833 "email": "${data["email"]}" 1834 }`; 1835 1836 // format first and last name 1837 data["fullname"] = data["fullname"].toLowerCase(); 1838 var fullname = data["fullname"].trim().split(/\s+/).filter(
1838Boolean).map((word) => { 1839 return word[0].toUpperCase() + word.substring(1); 1840 }); 1841 var firstname = fullname.slice(0, -1).join(" "); 1842 var lastname = fullname[fullname.length - 1]; 1843 1844 // get time now 1845 var timeSubmit = Date.now(); 1846 1847 // get utm properties 1848 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 1849 1850 // get contact 1851 jQuery.ajax({ 1852 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 1853 type: 'POST', 1854 contentType: 'application/json', 1855 dataType: 'json', 1856 data: dataGetContact, 1857 success: function(resp) { 1858 if (!resp['status'] && resp['status'] !== 'error') { 1859 // have contact 1860 if (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"])) { 1861 // update Sep 17 2023 1862 // don't have leadsource or leadsource can be override 1863 var dataSendToHubspot = `{ 1864 "email": "${data["email"]}", 1865 "properties": { 1866 "firstname": "${firstname}", 1867 "lastname": "${lastname}", 1868 "jobtitle": "${data["jobtitle"]}", 1869 "number_of_tester": "${data["number_of_tester"]}", 1870 "current_testing_challenges": "${data["challenges"]}", 1871 "self_reported_attribution": "${data["self_reported_attribution"]}", 1872 "leadsource": "${data["leadsource"]}", 1873 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1874 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1875 "last_time_submit": "${timeSubmit}" 1876 ${snippetUtm} 1877 } 1878 }`; 1879 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 1880 } else { 1881 // have leadsource -> don't override it 1882 } 1883 } else { 1884 // don't have contact 1885 // create new contact with leadsource 1886 var dataCreateContact = `{ 1887 "email": "${data["email"]}", 1888 "firstname": "${firstname}", 1889 "lastname": "${lastname}", 1890 "properties": { 1891 "jobtitle": "${data["jobtitle"]}", 1892 "number_of_tester": "${data["number_of_tester"]}", 1893 "current_testing_challenges": "${data["challenges"]}", 1894 "self_reported_attribution": "${data["self_reported_attribution"]}", 1895 "registration_status": "Non-register", 1896 "form_source": "Website", 1897 "leadsource": "${data["leadsource"]}", 1898 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1899 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1900 "last_time_submit": "${timeSubmit}" 1901 ${snippetUtm} 1902 } 1903 }`; 1904 1905 jQuery.ajax({ 1906 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 1907 type: 'POST', 1908 contentType: 'application/json', 1909 data: dataCreateContact, 1910 success: function(resp) { 1911 if (callback && typeof(callback) == "function") { 1912 callback(); 1913 } 1914 } 1915 }); 1916 } 1917 1918 } 1919 }); 1920 } 1921 1922 // this function send to Hubspot when user submti webinar ondemand form 1923 this.trackSubmitOndemandWebinar = function(data, callback) { 1924 var dataGetContact = `{ 1925 "email": "${data["email"]}" 1926 }`; 1927 1928 // format first and last name 1929 const fullname = []; 1930 data["fullname"].toLowerCase().trim().split(/\s+/).filter(
1930Boolean).map((word) => { 1931 fullname.push(word[0].toUpperCase() + word.substring(1)); 1932 }); 1933 let firstname = ""; 1934 let lastname = ""; 1935 fullname.map((name, index) => { 1936 if (index === 0) { 1937 firstname = name; 1938 } 1939 else if (index + 1 === fullname.length) { 1940 lastname += name; 1941 } 1942 else { 1943 lastname += name + " "; 1944 } 1945 }); 1946 1947 // get time now 1948 var timeSubmit = Date.now(); 1949 1950 // get utm properties 1951 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 1952 1953 // get contact 1954 jQuery.ajax({ 1955 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 1956 type: 'POST', 1957 contentType: 'application/json', 1958 dataType: 'json', 1959 data: dataGetContact, 1960 success: function(resp) { 1961 if (!resp['status'] && resp['status'] !== 'error') { 1962 let snippetLeadsource = ''; 1963 let currentActionList = ''; 1964 let upcomingWebinarNotification = ''; 1965 // have contact 1966 if (data["usebouncer_domain_type"] == 'business' && (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"]))) { 1967 // update Feb 7 2024 1968 // don't have leadsource or leadsource can be override 1969 snippetLeadsource = `,"leadsource": "${data["leadsource"]}",\n"leadsource_by_campaign": "${data["leadsource_by_campaign"]}",\n"last_time_submit": "${timeSubmit}"`; 1970 } 1971 1972 // update properties into this contact 1973 if (resp['properties']['non_signup_actions']) { 1974 // already have properties 1975 currentActionList = resp['properties']['non_signup_actions']['value']; 1976 } 1977 1978 // upcoming webinar notification 1979 if (data["upcoming_webinar_notification"]) { 1980 upcomingWebinarNotification = `,"upcoming_webinar_notification": "true"`; 1981 } 1982 1983 // check and append new action 1984 let newActionList = (currentActionList.indexOf(data['webinar_name']) == -1) ? currentActionList + `;${data['webinar_name']}` : currentActionList; 1985 1986 let dataSendToHubspot = `{ 1987 "email": "${data["email"]}", 1988 "properties": { 1989 "firstname": "${firstname}", 1990 "lastname": "${lastname}", 1991 "jobtitle": "${data["jobtitle"]}", 1992 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 1993 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 1994 "non_signup_actions": "${newActionList}" 1995 ${snippetLeadsource} 1996 ${upcomingWebinarNotification} 1997 ${snippetUtm} 1998 } 1999 }`; 2000 // soqr24 webinar 2001 if (data['webinar_name'] == 'Webinar Registration - SOQR24 Ondemand') { 2002 dataSendToHubspot = `{ 2003 "email": "${data["email"]}", 2004 "properties": { 2005 "firstname": "${firstname}", 2006 "lastname": "${lastname}", 2007 "jobtitle": "${data["jobtitle"]}", 2008 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2009 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2010 "which_stage_of_test_automation_best_describes_your_current_progress_": "${data["which_stage_of_test_automation_best_describes_your_current_progress_"]}", 2011 "soqr24_webinar_ondemand_submit_timestamp": "${timeSubmit}" 2012 ${snippetLeadsource} 2013 ${upcomingWebinarNotification} 2014 ${snippetUtm} 2015 } 2016 }`; 2017 } 2018 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2019 2020 // send for cold 2021 // action after cold 2022 let currentActionColdList = ''; 2023 if (resp['properties']['website_actions_after_cold']) { 2024 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 2025 } 2026 let newActionColdList = (currentActionColdList.indexOf(data['webinar_name']) == -1) ? currentActionColdList + `;${data['webinar_name']}` : currentActionColdList; 2027 let coldActionData = ''; 2028 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 2029 // call api update for cold lead only 2030 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`;
2031 let dataColdSendToHubspot = `{ 2032 "email": "${data["email"]}", 2033 "properties": { 2034 ${coldActionData} 2035 } 2036 }`; 2037 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 2038 } 2039 } else { 2040 // don't have contact 2041 // create new contact with action + leadsource (if needed) 2042 let snippetLeadsource = ''; 2043 let upcomingWebinarNotification = ''; 2044 if (data["usebouncer_domain_type"] == 'business') { 2045 snippetLeadsource = `,"leadsource": "${data["leadsource"]}",\n"leadsource_by_campaign": "${data["leadsource_by_campaign"] ?? 'Others'}",\n"last_time_submit": "${timeSubmit}"`; 2046 } 2047 // upcoming webinar notification 2048 if (data["upcoming_webinar_notification"]) { 2049 upcomingWebinarNotification = `,"upcoming_webinar_notification": "true"`; 2050 } 2051 let dataCreateContact = `{ 2052 "email": "${data["email"]}", 2053 "firstname": "${firstname}", 2054 "lastname": "${lastname}", 2055 "properties": { 2056 "jobtitle": "${data["jobtitle"]}", 2057 "registration_status": "Non-register", 2058 "form_source": "Website", 2059 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2060 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2061 "non_signup_actions": "${data['webinar_name']}" 2062 ${snippetLeadsource} 2063 ${upcomingWebinarNotification} 2064 ${snippetUtm} 2065 } 2066 }`; 2067 2068 // soqr24 webinar 2069 if (data['webinar_name'] == 'Webinar Registration - SOQR24 Ondemand') { 2070 dataCreateContact = `{ 2071 "email": "${data["email"]}", 2072 "firstname": "${firstname}", 2073 "lastname": "${lastname}", 2074 "properties": { 2075 "jobtitle": "${data["jobtitle"]}", 2076 "registration_status": "Non-register", 2077 "form_source": "Website", 2078 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2079 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2080 "which_stage_of_test_automation_best_describes_your_current_progress_": "${data["which_stage_of_test_automation_best_describes_your_current_progress_"]}", 2081 "soqr24_webinar_ondemand_submit_timestamp": "${timeSubmit}" 2082 ${snippetLeadsource} 2083 ${upcomingWebinarNotification} 2084 ${snippetUtm} 2085 } 2086 }`; 2087 } 2088 2089 jQuery.ajax({ 2090 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 2091 type: 'POST', 2092 contentType: 'application/json', 2093 data: dataCreateContact, 2094 success: function(resp) { 2095 if (callback && typeof(callback) == "function") { 2096 callback(); 2097 } 2098 } 2099 }); 2100 } 2101 2102 } 2103 }); 2104 } 2105 2106 // this fucntion send to Hubspot when user submit download katalon packages form (Signup exit popup) 2107 this.submitDownloadPackageSignUp = function(data, callback) { 2108 var dataGetContact = `{ 2109 "email": "${data["email"]}" 2110 }`; 2111 2112 // format first and last name 2113 /* data["fullname"] = data["fullname"].toLowerCase(); 2114 var fullname = data["fullname"].trim().split(/\s+/).filter(
2114Boolean).map((word) => { 2115 return word[0].toUpperCase() + word.substring(1); 2116 }); 2117 var firstname = fullname.slice(0, -1).join(" "); 2118 var lastname = fullname[fullname.length - 1]; */ 2119 2120 // get utm properties 2121 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 2122 2123 // get contact 2124 jQuery.ajax({ 2125 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 2126 type: 'POST', 2127 contentType: 'application/json', 2128 dataType: 'json', 2129 data: dataGetContact, 2130 success: function(resp) { 2131 //console.log(resp); 2132 var currentActionList = ''; 2133 if (!resp['status'] && resp['status'] !== 'error') { 2134 // have contact 2135 // update properties into this contact 2136 if (resp['properties']['non_signup_actions']) { 2137 // already have properties 2138 currentActionList = resp['properties']['non_signup_actions']['value']; 2139 } 2140 2141 // already check KS for QA Lead 2142 var newActionList = (currentActionList.indexOf(data['exit_popup_name']) == -1) ? currentActionList + `;${data['exit_popup_name']}` : currentActionList; 2143 2144 2145 var dataSendToHubspot = `{ 2146 "email": "${data["email"]}", 2147 "properties": { 2148 "non_signup_actions": "${newActionList}" 2149 ${snippetUtm} 2150 } 2151 }`; 2152 2153 //console.log(dataSendToHubspot); 2154 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2155 2156 // send for cold 2157 // action after cold 2158 let currentActionColdList = ''; 2159 if (resp['properties']['website_actions_after_cold']) { 2160 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 2161 } 2162 let newActionColdList = (currentActionColdList.indexOf(data['exit_popup_name']) == -1) ? currentActionColdList + `;${data['exit_popup_name']}` : currentActionColdList; 2163 let coldActionData = ''; 2164 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 2165 // call api update for cold lead only 2166 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`; 2167 let dataColdSendToHubspot = `{ 2168 "email": "${data["email"]}", 2169 "properties": { 2170 ${coldActionData} 2171 } 2172 }`; 2173 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 2174 } 2175 } else { 2176 // contact not exisit 2177 // create a new contact 2178 var dataCreateContact = `{ 2179 "email": "${data["email"]}", 2180 "firstname": "", 2181 "lastname": "", 2182 "properties": { 2183 "non_signup_actions": "${data['exit_popup_name']}", 2184 "registration_status": "Non-register", 2185 "form_source": "Website" 2186 ${snippetUtm} 2187 } 2188 }`; 2189 2190 //console.log(dataCreateContact); 2191 2192 jQuery.ajax({ 2193 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 2194 type: 'POST', 2195 contentType: 'application/json', 2196 data: dataCreateContact, 2197 success: function(resp) { 2198 if (callback && typeof(callback) == "function") { 2199 callback(); 2200 } 2201 } 2202 }); 2203 } 2204 2205 } 2206 }); 2207 } 2208 2209 // this function tracking leadsource to hubspot 2210 this.trackLeadSource = function(data, callback) { 2211 var dataGetContact = `{ 2212 "email": "${data["email"]}" 2213 }`; 2214 var leadsource_by_campaign = data["leadsource_by_campaign"] ? data["leadsource_by_campaign"] : 'Others'; 2215 // get contact 2216 jQuery.ajax({ 2217 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 2218 type: 'POST', 2219 contentType: 'application/json', 2220 dataType: 'json', 2221 data: dataGetContact, 2222 success: function(resp) { 2223 if (!resp['status'] && resp['status'] !== 'error' && (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"]))) { 2224 // update Sep 17 2023 2225 // have contact and don't have leadsource or leadsource can be override 2226 var dataSendToHubspot = `{ 2227 "email": "${data["email"]}", 2228 "properties": { 2229 "leadsource": "${data["leadsource"]}", 2230 "leadsource_by_campaign": "${leadsource_by_campaign}" 2231 } 2232 }`; 2233 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2234 } else { 2235 // don't have contact 2236 // do nothing 2237 } 2238 2239 if (callback && typeof(callback) == "function") { 2240 callback(); 2241 } 2242 } 2243 }); 2244 } 2245 2246 // function tracking user submit roi form 2247 this.trackSubmitROI = function(data, callback) { 2248 var dataGetContact = `{ 2249 "email": "${data["email"]}" 2250 }`; 2251 2252 // format first and last name 2253 data["fullname"] = data["fullname"].toLowerCase(); 2254 var fullname = data["fullname"].trim().split(/\s+/).filter(
2254Boolean).map((word) => { 2255 return word[0].toUpperCase() + word.substring(1); 2256 }); 2257 var firstname = fullname.slice(0, -1).join(" "); 2258 var lastname = fullname[fullname.length - 1]; 2259 2260 // get utm properties 2261 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 2262 2263 // get contact 2264 jQuery.ajax({ 2265 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 2266 type: 'POST', 2267 contentType: 'application/json', 2268 dataType: 'json', 2269 data: dataGetContact, 2270 success: function(resp) { 2271 //console.log(resp); 2272 var currentActionList = ''; 2273 if (!resp['status'] && resp['status'] !== 'error') { 2274 // have contact 2275 // update properties into this contact 2276 if (resp['properties']['non_signup_actions']) { 2277 // already have properties 2278 currentActionList = resp['properties']['non_signup_actions']['value']; 2279 } 2280 2281 // already check current action 2282 var newActionList = (currentActionList.indexOf(data['roi_name']) == -1) ? currentActionList + `;${data['roi_name']}` : currentActionList; 2283 2284 2285 var dataSendToHubspot = `{ 2286 "email": "${data["email"]}", 2287 "properties": { 2288 "firstname": "${firstname}", 2289 "lastname": "${lastname}", 2290 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2291 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2292 "non_signup_actions": "${newActionList}" 2293 ${snippetUtm} 2294 } 2295 }`; 2296 2297 //console.log(dataSendToHubspot); 2298 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2299 2300 // send for cold 2301 // action after cold 2302 let currentActionColdList = ''; 2303 if (resp['properties']['website_actions_after_cold']) { 2304 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 2305 } 2306 let newActionColdList = (currentActionColdList.indexOf(data['roi_name']) == -1) ? currentActionColdList + `;${data['roi_name']}` : currentActionColdList; 2307 let coldActionData = ''; 2308 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 2309 // call api update for cold lead only 2310 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`; 2311 let dataColdSendToHubspot = `{ 2312 "email": "${data["email"]}", 2313 "properties": { 2314 ${coldActionData} 2315 } 2316 }`; 2317 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 2318 } 2319 } else { 2320 // contact not exist 2321 2322 // create a new contact 2323 var dataCreateContact = `{ 2324 "email": "${data["email"]}", 2325 "firstname": "${firstname}", 2326 "lastname": "${lastname}", 2327 "properties": { 2328 "non_signup_actions": "${data['roi_name']}", 2329 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2330 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2331 "registration_status": "Non-register", 2332 "form_source": "Website" 2333 ${snippetUtm} 2334 } 2335 }`; 2336 2337 //console.log(dataCreateContact); 2338 2339 jQuery.ajax({ 2340 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 2341 type: 'POST', 2342 contentType: 'application/json', 2343 data: dataCreateContact, 2344 success: function(resp) { 2345 if (callback && typeof(callback) == "function") { 2346 callback(); 2347 } 2348 } 2349 }); 2350 } 2351 2352 } 2353 }); 2354 } 2355 2356 // this function to update Hubspot and check already leadsource 2357 this.trackLeadSourceByCampaign = function(data, callback) { 2358 var dataGetContact = `{ 2359 "email": "${data["email"]}" 2360 }`; 2361 let timeSubmit = Date.now(); 2362 // get contact 2363 jQuery.ajax({ 2364 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 2365 type: 'POST', 2366 contentType: 'application/json', 2367 dataType: 'json', 2368 data: dataGetContact, 2369 success: function(resp) { 2370 if (!resp['status'] && resp['status'] !== 'error') { 2371 if (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"])) { 2372 // update Sep 17 2023 2373 // have contact and don't have leadsource or leadsource can be override 2374 var dataSendToHubspot = `{ 2375 "email": "${data["email"]}", 2376 "properties": { 2377 "leadsource": "${data["leadsource"]}", 2378 "leadsource_by_campaign": "${data["leadsource_by_campaign"]}", 2379 "last_time_submit": "${timeSubmit}" 2380 } 2381 }`; 2382 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2383 } 2384 2385 // update leadsource 2nd for cold 2386 if (katalonHubspot.isOverridableLeadsourceForCold(resp['properties'], data["leadsource"])) {
2387 let dataColdSendToHubspot = `{ 2388 "email": "${data["email"]}", 2389 "properties": { 2390 "leadsource_2nd": "${data["leadsource"]}", 2391 "leadsource_by_campaign_2nd": "${data["leadsource_by_campaign"]}", 2392 "last_time_cold_submit": "${timeSubmit}" 2393 } 2394 }`; 2395 katalonHubspot.sendToHubspot(dataColdSendToHubspot, callback); 2396 } 2397 } 2398 2399 if (callback && typeof(callback) == "function") { 2400 callback(); 2401 } 2402 } 2403 }); 2404 } 2405 2406 // this function to update Hubspot and check already leadsource 2407 this.trackLeadSourceOnly = function(data, callback) { 2408 var dataGetContact = `{ 2409 "email": "${data["email"]}" 2410 }`; 2411 let timeSubmit = Date.now(); 2412 // get contact 2413 jQuery.ajax({ 2414 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 2415 type: 'POST', 2416 contentType: 'application/json', 2417 dataType: 'json', 2418 data: dataGetContact, 2419 success: function(resp) { 2420 if (!resp['status'] && resp['status'] !== 'error') { 2421 if (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"])) { 2422 // update Sep 17 2023 2423 // have contact and don't have leadsource or leadsource can be override 2424 var dataSendToHubspot = `{ 2425 "email": "${data["email"]}", 2426 "properties": { 2427 "leadsource": "${data["leadsource"]}", 2428 "leadsource_by_campaign": "Others", 2429 "last_time_submit": "${timeSubmit}" 2430 } 2431 }`; 2432 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2433 } 2434 2435 // update leadsource 2nd for cold 2436 if (katalonHubspot.isOverridableLeadsourceForCold(resp['properties'], data["leadsource"])) { 2437 let dataColdSendToHubspot = `{ 2438 "email": "${data["email"]}", 2439 "properties": { 2440 "leadsource_2nd": "${data["leadsource"]}", 2441 "leadsource_by_campaign_2nd": "Others", 2442 "last_time_cold_submit": "${timeSubmit}" 2443 } 2444 }`; 2445 katalonHubspot.sendToHubspot(dataColdSendToHubspot, callback); 2446 } 2447 } 2448 2449 if (callback && typeof(callback) == "function") { 2450 callback(); 2451 } 2452 } 2453 }); 2454 } 2455 2456 // this function to update Hubspot and check already leadsource (updated) 2457 this.trackLeadSourceRequestDemo = function(data, callback) { 2458 const dataGetContact = `{ 2459 "email": "${data["email"]}" 2460 }`; 2461 2462 const fullname = []; 2463 2464 data["fullname"].toLowerCase().trim().split(/\s+/).filter(Boolean).map((word) => { 2465 fullname.push(word[0].toUpperCase() + word.substring(1)); 2466 }); 2467 2468 let firstname = ""; 2469 let lastname = ""; 2470 2471 fullname.map((name, index) => { 2472 if (index === 0) { 2473 firstname = name; 2474 } 2475 else if (index + 1 === fullname.length) { 2476 lastname += name; 2477 } 2478 else { 2479 lastname += name + " "; 2480 } 2481 }); 2482 2483 if (!data["leadsource_by_campaign"]) { 2484 data["leadsource_by_campaign"] = "Others"; 2485 } 2486 2487 const snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 2488 2489 // get time now 2490 let timeSubmit = Date.now(); 2491 2492 // get contact 2493 jQuery.ajax({ 2494 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 2495 type: 'POST', 2496 contentType: 'application/json', 2497 dataType: 'json', 2498 data: dataGetContact, 2499 success: function(resp) { 2500 if (!resp['status'] && resp['status'] !== 'error') { 2501 if (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"])) { 2502 // update Sep 17 2023 2503 // have contact and don't have leadsource or leadsource can be override 2504 const dataSendToHubspot = `{ 2505 "email": "${data["email"]}", 2506 "properties": { 2507 "firstname": "${firstname}", 2508 "lastname": "${lastname}", 2509 "self_reported_attribution": "${data["self_reported_attribution"]}", 2510 "custom_company_country": "${data["custom_company_country"] ?? ''}", 2511 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 2512 "leadsource": "${data["leadsource"]}", 2513 "leadsource_by_campaign": "${data["leadsource_by_campaign"]}", 2514 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2515 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2516 "last_time_submit": "${timeSubmit}" 2517 ${snippetUtm} 2518 } 2519 }`; 2520 2521 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2522 } 2523 2524 // update leadsource 2nd for cold 2525 if (katalonHubspot.isOverridableLeadsourceForCold(resp['properties'], data["leadsource"])) {
2526 let dataColdSendToHubspot = `{ 2527 "email": "${data["email"]}", 2528 "properties": { 2529 "firstname": "${firstname}", 2530 "lastname": "${lastname}", 2531 "self_reported_attribution": "${data["self_reported_attribution"]}", 2532 "custom_company_country": "${data["custom_company_country"] ?? ''}", 2533 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 2534 "leadsource_2nd": "${data["leadsource"]}", 2535 "leadsource_by_campaign_2nd": "${data["leadsource_by_campaign"]}", 2536 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2537 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2538 "last_time_cold_submit": "${timeSubmit}" 2539 ${snippetUtm} 2540 } 2541 }`; 2542 katalonHubspot.sendToHubspot(dataColdSendToHubspot, callback); 2543 } 2544 } else { 2545 // contact not exisit 2546 // create a new contact 2547 const dataCreateContact = `{ 2548 "email": "${data["email"]}", 2549 "firstname": "${firstname}", 2550 "lastname": "${lastname}", 2551 "properties": { 2552 "self_reported_attribution": "${data["self_reported_attribution"]}", 2553 "custom_company_country": "${data["custom_company_country"] ?? ''}", 2554 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 2555 "registration_status": "Non-register", 2556 "leadsource": "${data["leadsource"]}", 2557 "leadsource_by_campaign": "${data["leadsource_by_campaign"]}", 2558 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2559 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2560 "form_source": "Website", 2561 "last_time_submit": "${timeSubmit}" 2562 ${snippetUtm} 2563 } 2564 }`; 2565 2566 jQuery.ajax({ 2567 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 2568 type: 'POST', 2569 contentType: 'application/json', 2570 data: dataCreateContact, 2571 success: function(resp) { 2572 if (callback && typeof(callback) == "function") { 2573 callback(); 2574 } 2575 } 2576 }); 2577 } 2578 2579 if (callback && typeof(callback) == "function") { 2580 callback(); 2581 } 2582 } 2583 }); 2584 } 2585 2586 // this function to tracking submit SAGA Recording 2587 this.trackRequestDemoSubmitForSAGA = function(data, callback) { 2588 const dataGetContact = `{ 2589 "email": "${data["email"]}" 2590 }`; 2591 2592 const fullname = []; 2593 2594 data["fullname"].toLowerCase().trim().split(/\s+/).filter(Boolean).map((word) => { 2595 fullname.push(word[0].toUpperCase() + word.substring(1)); 2596 }); 2597 2598 let firstname = ""; 2599 let lastname = ""; 2600 2601 fullname.map((name, index) => { 2602 if (index === 0) { 2603 firstname = name; 2604 } 2605 else if (index + 1 === fullname.length) { 2606 lastname += name; 2607 } 2608 else { 2609 lastname += name + " "; 2610 } 2611 }); 2612 2613 const snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 2614 2615 // get time now 2616 let timeSubmit = Date.now(); 2617 2618 // get contact 2619 jQuery.ajax({ 2620 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 2621 type: 'POST', 2622 contentType: 'application/json', 2623 dataType: 'json', 2624 data: dataGetContact, 2625 success: function(resp) { 2626 if (!resp['status'] && resp['status'] !== 'error') { 2627 if (katalonHubspot.isOverridableLeadsource(resp['properties'], data["leadsource"])) { 2628 // update Sep 17 2023 2629 // have contact and don't have leadsource or leadsource can be override 2630 const dataSendToHubspot = `{ 2631 "email": "${data["email"]}", 2632 "firstname": "${firstname}", 2633 "lastname": "${lastname}", 2634 "properties": { 2635 "abm_2023_saga_recording_submit_time": "${data["abm_2023_saga_recording_submit_time"]}", 2636 "abm_2023_custom_demo_request_time": "${data["abm_2023_custom_demo_request_time"]}", 2637 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2638 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2639 "last_time_submit": "${timeSubmit}" 2640 ${snippetUtm} 2641 } 2642 }`; 2643 2644 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2645 } 2646 } 2647 else { 2648 // contact not exisit 2649 // create a new contact 2650 const dataCreateContact = `{ 2651 "email": "${data["email"]}", 2652 "firstname": "${firstname}", 2653 "lastname": "${lastname}", 2654 "properties": { 2655 "registration_status": "Non-register", 2656 "abm_2023_saga_recording_submit_time": "${data["abm_2023_saga_recording_submit_time"]}", 2657 "abm_2023_custom_demo_request_time": "${data["abm_2023_custom_demo_request_time"]}", 2658 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2659 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2660 "form_source": "Website", 2661 "last_time_submit": "${timeSubmit}" 2662 ${snippetUtm} 2663 } 2664 }`; 2665 2666 jQuery.ajax({ 2667 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 2668 type: 'POST', 2669 contentType: 'application/json', 2670 data: dataCreateContact, 2671 success: function(resp) { 2672 if (callback && typeof(callback) == "function") { 2673 callback(); 2674 } 2675 } 2676 }); 2677 } 2678 2679 if (callback && typeof(callback) == "function") { 2680 callback(); 2681 } 2682 } 2683 }); 2684 } 2685 2686 // function track user's score in Bug Hunter game 2687 this.trackBugHunter = function(data, callback) { 2688 const date = Date.now(); 2689 2690 let dataGetContact = `{ 2691 "email": "${data["email"]}" 2692 }`; 2693
2694 let dataSendToHubspot = `{ 2695 "email": "${data["email"]}", 2696 "properties": { 2697 "bug_hunter_username": "${data["username"]}", 2698 "bug_hunter_score": "${data["score"]}", 2699 "bug_hunter_timestamp": "${date}" 2700 } 2701 }`; 2702 2703 // check if contact exists 2704 jQuery.ajax({ 2705 url: katObject.webAPI + "/wp-json/restful_api/v1/hubspot/get-contact", 2706 type: "POST", 2707 contentType: "application/json", 2708 dataType: "json", 2709 data: dataGetContact, 2710 success: function(resp) { 2711 if (!resp["status"] && resp["status"] !== "error") { // contact exists 2712 if (resp["properties"]["bug_hunter_username"]) { // if user already submitted once 2713 if (resp["properties"]["bug_hunter_score"]["value"] < data["score"]) { // if new score > old score 2714 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); // update bug hunter score 2715 } 2716 else { // doesn't update score 2717 callback(); 2718 } 2719 } 2720 else { // user has never submitted 2721 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); // update existing contact with new bug hunter username and score 2722 } 2723 } 2724 else { // contact doesn't exist 2725 let dataCreateContact = `{ 2726 "email": "${data["email"]}", 2727 "properties": { 2728 "bug_hunter_username": "${data["username"]}", 2729 "bug_hunter_score": "${data["score"]}", 2730 "bug_hunter_timestamp": "${date}", 2731 "registration_status": "Non-register", 2732 "form_source": "Website" 2733 } 2734 }`; 2735 jQuery.ajax({ // create new contact with bug hunter username and score 2736 url: katObject.webAPI + "/wp-json/restful_api/v1/hubspot/create-contact", 2737 type: "POST", 2738 contentType: "application/json", 2739 data: dataCreateContact, 2740 success: function(resp) { 2741 if (!resp["status"] && resp["status"] !== "error") { 2742 callback(); 2743 } 2744 } 2745 }); 2746 } 2747 } 2748 }); 2749 } 2750 2751 // track submit Talk to Expert form in Katalon for Enterprises LP 2752 this.trackSubmitKatalonForEnterprisesForm = function(data, callback) { 2753 let fullname = []; 2754 2755 data["fullname"].toLowerCase().trim().split(/\s+/).filter(Boolean).map((word) => { 2756 fullname.push(word[0].toUpperCase() + word.substring(1)); 2757 }); 2758 2759 let firstname = ""; 2760 let lastname = ""; 2761 2762 fullname.map((name, index) => { 2763 if (index === 0) { 2764 firstname = name; 2765 } 2766 else if (index + 1 === fullname.length) { 2767 lastname += name; 2768 } 2769 else { 2770 lastname += name + " "; 2771 } 2772 }); 2773 2774 let snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 2775 2776 let dataGetContact = `{ 2777 "email": "${data["email"]}" 2778 }`; 2779 2780 let dataSendToHubspot = `{ 2781 "email": "${data["email"]}", 2782 "firstname": "${firstname}", 2783 "lastname": "${lastname}", 2784 "properties": { 2785 "leadsource": "${data["leadsource"]}", 2786 "leadsource_by_campaign": "${data["leadsource_by_campaign"]}", 2787 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2788 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}" 2789 ${snippetUtm} 2790 } 2791 }`; 2792 2793 jQuery.ajax({ 2794 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 2795 type: 'POST', 2796 contentType: 'application/json', 2797 dataType: 'json', 2798 data: dataGetContact, 2799 success: function(resp) { 2800 if (!resp["status"] && resp["status"] !== "error") { // contact exists 2801 if (!resp["properties"]["leadsource"]) { // no lead source 2802 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2803 } 2804 else { // lead source exists, doesn't send 2805 callback(); 2806 } 2807 } 2808 else { // contact doesn't exist 2809 let dataCreateContact = `{ 2810 "email": "${data["email"]}", 2811 "firstname": "${firstname}", 2812 "lastname": "${lastname}", 2813 "properties": { 2814 "leadsource": "${data["leadsource"]}", 2815 "leadsource_by_campaign": "${data["leadsource_by_campaign"]}", 2816 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2817 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2818 "registration_status": "Non-register" 2819 ${snippetUtm} 2820 } 2821 }`; 2822 2823 jQuery.ajax({ 2824 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 2825 type: 'POST', 2826 contentType: 'application/json', 2827 data: dataCreateContact, 2828 success: function(resp) { 2829 if (callback && typeof(callback) == "function") { 2830 callback(); 2831 } 2832 } 2833 }); 2834 } 2835 } 2836 }); 2837 } 2838 2839 // this function to tracking submit ABM 2840 this.trackingSubmitABM = function(data, callback) { 2841 var dataGetContact = `{ 2842 "email": "${data["email"]}" 2843 }`; 2844 2845 // format first and last name 2846 data["fullname"] = data["fullname"].toLowerCase(); 2847 var fullname = data["fullname"].trim().split(/\s+/).filter(
2847Boolean).map((word) => { 2848 return word[0].toUpperCase() + word.substring(1); 2849 }); 2850 var firstname = fullname.slice(0, -1).join(" "); 2851 var lastname = fullname[fullname.length - 1]; 2852 2853 // get utm properties 2854 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 2855 2856 // get contact 2857 jQuery.ajax({ 2858 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 2859 type: 'POST', 2860 contentType: 'application/json', 2861 dataType: 'json', 2862 data: dataGetContact, 2863 success: function(resp) { 2864 //console.log(resp); 2865 var currentActionList = ''; 2866 if (!resp['status'] && resp['status'] !== 'error') { 2867 2868 var dataSendToHubspot = `{ 2869 "email": "${data["email"]}", 2870 "properties": { 2871 "firstname": "${firstname}", 2872 "lastname": "${lastname}", 2873 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2874 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2875 "number_of_tester": "${data["number_of_tester"]}", 2876 "current_testing_challenges": "${data["challenges"]}", 2877 "self_reported_attribution": "${data["self_reported_attribution"]}", 2878 "abm_contact_sales_timestamps": "${data["abm_contact_sales_timestamps"]}", 2879 "last_time_submit": "${data["abm_contact_sales_timestamps"]}", 2880 "abm_submit_source": "${data["abm_submit_source"]}" 2881 ${snippetUtm} 2882 } 2883 }`; 2884 2885 //console.log(dataSendToHubspot); 2886 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2887 } else { 2888 // contact not exist 2889 2890 // create a new contact 2891 var dataCreateContact = `{ 2892 "email": "${data["email"]}", 2893 "firstname": "${firstname}", 2894 "lastname": "${lastname}", 2895 "properties": { 2896 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2897 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2898 "registration_status": "Non-register", 2899 "form_source": "Website", 2900 "number_of_tester": "${data["number_of_tester"]}", 2901 "current_testing_challenges": "${data["challenges"]}", 2902 "self_reported_attribution": "${data["self_reported_attribution"]}", 2903 "abm_contact_sales_timestamps": "${data["abm_contact_sales_timestamps"]}", 2904 "last_time_submit": "${data["abm_contact_sales_timestamps"]}", 2905 "abm_submit_source": "${data["abm_submit_source"]}" 2906 ${snippetUtm} 2907 } 2908 }`; 2909 2910 //console.log(dataCreateContact); 2911 2912 jQuery.ajax({ 2913 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 2914 type: 'POST', 2915 contentType: 'application/json', 2916 data: dataCreateContact, 2917 success: function(resp) { 2918 if (callback && typeof(callback) == "function") { 2919 callback(); 2920 } 2921 } 2922 }); 2923 } 2924 2925 } 2926 }); 2927 } 2928 2929 // this fucntion send to Hubspot when user submit CTMA Form 2930 this.submitCTMAForm = function(data, callback) { 2931 var dataGetContact = `{ 2932 "email": "${data["email"]}" 2933 }`; 2934 2935 // format first and last name 2936 data["fullname"] = data["fullname"].toLowerCase(); 2937 var fullname = data["fullname"].trim().split(/\s+/).filter(
2937Boolean).map((word) => { 2938 return word[0].toUpperCase() + word.substring(1); 2939 }); 2940 var firstname = fullname.slice(0, -1).join(" "); 2941 var lastname = fullname[fullname.length - 1]; 2942 2943 // get utm properties 2944 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 2945 2946 // get contact 2947 jQuery.ajax({ 2948 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 2949 type: 'POST', 2950 contentType: 'application/json', 2951 dataType: 'json', 2952 data: dataGetContact, 2953 success: function(resp) { 2954 //console.log(resp); 2955 var currentActionList = ''; 2956 if (!resp['status'] && resp['status'] !== 'error') { 2957 // have contact 2958 // update properties into this contact 2959 if (resp['properties']['non_signup_actions']) { 2960 // already have properties 2961 currentActionList = resp['properties']['non_signup_actions']['value']; 2962 } 2963 2964 // already check KS for QA Lead 2965 var newActionList = (currentActionList.indexOf(data['action_name']) == -1) ? currentActionList + `;${data['action_name']}` : currentActionList; 2966 2967 2968 var dataSendToHubspot = `{ 2969 "email": "${data["email"]}", 2970 "properties": { 2971 "firstname": "${firstname}", 2972 "lastname": "${lastname}", 2973 "self_reported_attribution": "${data["self_reported_attribution"]}", 2974 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 2975 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 2976 "non_signup_actions": "${newActionList}" 2977 ${snippetUtm} 2978 } 2979 }`; 2980 2981 //console.log(dataSendToHubspot); 2982 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 2983 2984 // send for cold 2985 // action after cold 2986 let currentActionColdList = ''; 2987 if (resp['properties']['website_actions_after_cold']) { 2988 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 2989 } 2990 let newActionColdList = (currentActionColdList.indexOf(data['action_name']) == -1) ? currentActionColdList + `;${data['action_name']}` : currentActionColdList; 2991 let coldActionData = ''; 2992 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 2993 // call api update for cold lead only 2994 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`; 2995 let dataColdSendToHubspot = `{ 2996 "email": "${data["email"]}", 2997 "properties": { 2998 ${coldActionData} 2999 } 3000 }`; 3001 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 3002 } 3003 } else { 3004 // contact not exisit 3005 // create a new contact 3006 var dataCreateContact = `{ 3007 "email": "${data["email"]}", 3008 "firstname": "${firstname}", 3009 "lastname": "${lastname}", 3010 "properties": { 3011 "non_signup_actions": "${data['action_name']}", 3012 "self_reported_attribution": "${data["self_reported_attribution"]}", 3013 "registration_status": "Non-register", 3014 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3015 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3016 "form_source": "Website" 3017 ${snippetUtm} 3018 } 3019 }`; 3020 3021 //console.log(dataCreateContact); 3022 3023 jQuery.ajax({ 3024 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 3025 type: 'POST', 3026 contentType: 'application/json', 3027 data: dataCreateContact, 3028 success: function(resp) { 3029 if (callback && typeof(callback) == "function") { 3030 callback(); 3031 } 3032 } 3033 }); 3034 } 3035 3036 } 3037 }); 3038 } 3039 3040 // function to send identify 3041 this.trackIdentify = function(data, callback) { 3042 var dataSubmit = { 3043 submittedAt: Date.now(), 3044 fields: [ 3045 { 3046 objectTypeId: "0-1", 3047 name: "email", 3048 value: data['email'] 3049 } 3050 ], 3051 context: { 3052 hutk: data['hubspotutk'] 3053 } 3054 } 3055 // submit to form 3056 jQuery.ajax({ 3057 url: 'https://api.hsforms.com/submissions/v3/integration/submit/2465122/05359594-6970-4e6f-a51b-1b144d9e1e4c', 3058 type: 'POST', 3059 contentType: 'application/json', 3060 data: JSON.stringify(dataSubmit), 3061 success: function(resp) { 3062 if (callback && typeof(callback) == "function") { 3063 callback(); 3064 } 3065 }, 3066 fail: function() { 3067 if (callback && typeof(callback) == "function") { 3068 callback(); 3069 } 3070 }, 3071 error: function() { 3072 if (callback && typeof(callback) == "function") { 3073 callback(); 3074 } 3075 } 3076 }); 3077 } 3078 3079 // this function to tracking submit ABM Ebook 2023 3080 this.trackingSubmitABM2023 = function(data, callback) { 3081 var dataGetContact = `{ 3082 "email": "${data["email"]}" 3083 }`; 3084 3085 // format first and last name 3086 let fullname = []; 3087 3088 data["fullname"].toLowerCase().trim().split(/\s+/).filter(
3088Boolean).map((word) => { 3089 fullname.push(word[0].toUpperCase() + word.substring(1)); 3090 }); 3091 3092 let firstname = ""; 3093 let lastname = ""; 3094 3095 fullname.map((name, index) => { 3096 if (index === 0) { 3097 firstname = name; 3098 } 3099 else if (index + 1 === fullname.length) { 3100 lastname += name; 3101 } 3102 else { 3103 lastname += name + " "; 3104 } 3105 }); 3106 3107 // get utm properties 3108 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 3109 3110 // get contact 3111 jQuery.ajax({ 3112 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 3113 type: 'POST', 3114 contentType: 'application/json', 3115 dataType: 'json', 3116 data: dataGetContact, 3117 success: function(resp) { 3118 //console.log(resp); 3119 var currentActionList = ''; 3120 if (!resp['status'] && resp['status'] !== 'error') { 3121 3122 var dataSendToHubspot = `{ 3123 "email": "${data["email"]}", 3124 "properties": { 3125 "firstname": "${firstname}", 3126 "lastname": "${lastname}", 3127 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3128 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3129 "abm_2023_download_ebook_time": "${data["abm_2023_download_ebook_time"]}", 3130 "abm_2023_campaign_name": "${data["abm_2023_campaign_name"]}", 3131 "abm_2023_download_ebook_source": "${data["abm_2023_download_ebook_source"]}" 3132 ${snippetUtm} 3133 } 3134 }`; 3135 3136 //console.log(dataSendToHubspot); 3137 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 3138 } else { 3139 // contact not exist 3140 // create a new contact 3141 var dataCreateContact = `{ 3142 "email": "${data["email"]}", 3143 "firstname": "${firstname}", 3144 "lastname": "${lastname}", 3145 "properties": { 3146 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3147 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3148 "registration_status": "Non-register", 3149 "form_source": "Website", 3150 "abm_2023_download_ebook_time": "${data["abm_2023_download_ebook_time"]}", 3151 "abm_2023_campaign_name": "${data["abm_2023_campaign_name"]}", 3152 "abm_2023_download_ebook_source": "${data["abm_2023_download_ebook_source"]}" 3153 ${snippetUtm} 3154 } 3155 }`; 3156 3157 //console.log(dataCreateContact); 3158 3159 jQuery.ajax({ 3160 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 3161 type: 'POST', 3162 contentType: 'application/json', 3163 data: dataCreateContact, 3164 success: function(resp) { 3165 if (callback && typeof(callback) == "function") { 3166 callback(); 3167 } 3168 } 3169 }); 3170 } 3171 3172 } 3173 }); 3174 } 3175 3176 // track when user submit ABM request demo 3177 this.trackSubmitRequestDemoABM = function(data, callback) { 3178 const dataGetContact = `{ 3179 "email": "${data["email"]}" 3180 }`; 3181 3182 const capitalizeFirstLetter = (string) => { 3183 return string.charAt(0).toUpperCase() + string.slice(1); 3184 } 3185 3186 // format first and last name 3187 const fullname = []; 3188 3189 data["fullname"].toLowerCase().trim().split(/\s+/).filter(
3189Boolean).map((word) => { 3190 fullname.push(word[0].toUpperCase() + word.substring(1)); 3191 }); 3192 3193 let firstname = ""; 3194 let lastname = ""; 3195 3196 fullname.map((name, index) => { 3197 if (index === 0) { 3198 firstname = name; 3199 } 3200 else if (index + 1 === fullname.length) { 3201 lastname += name; 3202 } 3203 else { 3204 lastname += name + " "; 3205 } 3206 }); 3207 3208 // get utm properties 3209 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 3210 3211 // get time now 3212 let timeSubmit = Date.now(); 3213 3214 jQuery.ajax({ 3215 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 3216 type: 'POST', 3217 contentType: 'application/json', 3218 dataType: 'json', 3219 data: dataGetContact, 3220 success: function(resp) { 3221 if (!resp['status'] && resp['status'] !== 'error') { 3222 // have contact 3223 const dataSendToHubspot = `{ 3224 "email": "${data["email"]}", 3225 "properties": { 3226 "firstname": "${firstname}", 3227 "lastname": "${lastname}", 3228 "self_reported_attribution": "${data["self_reported_attribution"]}", 3229 "custom_company_country": "${data["custom_company_country"] ?? ''}", 3230 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 3231 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3232 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3233 "abm_2023_custom_demo_request_time": "${data["abm_2023_custom_demo_request_time"]}", 3234 "last_time_submit": "${timeSubmit}" 3235 ${snippetUtm} 3236 } 3237 }`; 3238 3239 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 3240 } 3241 else { 3242 // contact not exisit 3243 // create a new contact 3244 const dataCreateContact = `{ 3245 "email": "${data["email"]}", 3246 "firstname": "${firstname}", 3247 "lastname": "${lastname}", 3248 "properties": { 3249 "registration_status": "Non-register", 3250 "self_reported_attribution": "${data["self_reported_attribution"]}", 3251 "custom_company_country": "${data["custom_company_country"] ?? ''}", 3252 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 3253 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3254 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3255 "abm_2023_custom_demo_request_time": "${data["abm_2023_custom_demo_request_time"]}", 3256 "form_source": "Website", 3257 "last_time_submit": "${timeSubmit}" 3258 ${snippetUtm} 3259 } 3260 }`; 3261 3262 jQuery.ajax({ 3263 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 3264 type: 'POST', 3265 contentType: 'application/json', 3266 data: dataCreateContact, 3267 success: function(resp) { 3268 if (callback && typeof(callback) == "function") { 3269 callback(); 3270 } 3271 } 3272 }); 3273 } 3274 } 3275 }); 3276 } 3277 3278 // track when user submit Customer Marketing Book Call TO 3279 this.trackSubmitCustomerMarketingBookCall = function(data, callback) { 3280 const dataGetContact = `{ 3281 "email": "${data["email"]}" 3282 }`; 3283 3284 const capitalizeFirstLetter = (string) => { 3285 return string.charAt(0).toUpperCase() + string.slice(1); 3286 } 3287 3288 // format first and last name 3289 const fullName = data["full_name"].toLowerCase(); 3290 const names = fullName.trim().split(/\s+/); 3291 3292 const firstName = capitalizeFirstLetter(names[0]); 3293 const remainingNames = names.slice(1); 3294
3295 remainingNames.forEach((name, index) => remainingNames[index] = capitalizeFirstLetter(name)); 3296 const lastName = remainingNames.join(" "); 3297 3298 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 3299 3300 jQuery.ajax({ 3301 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 3302 type: 'POST', 3303 contentType: 'application/json', 3304 dataType: 'json', 3305 data: dataGetContact, 3306 success: function(resp) { 3307 if (!resp['status'] && resp['status'] !== 'error') { 3308 // have contact 3309 const dataSendToHubspot = `{ 3310 "email": "${data["email"]}", 3311 "properties": { 3312 "firstname": "${firstName}", 3313 "lastname": "${lastName}", 3314 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3315 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3316 "customer_marketing_book_call_time": "${data["customer_marketing_book_call_time"]}", 3317 "customer_marketing_book_call_campaign": "${data["customer_marketing_book_call_campaign"]}" 3318 ${snippetUtm} 3319 } 3320 }`; 3321 3322 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 3323 } 3324 else { 3325 // contact not exisit 3326 // create a new contact 3327 const dataCreateContact = `{ 3328 "email": "${data["email"]}", 3329 "firstname": "${firstName}", 3330 "lastname": "${lastName}", 3331 "properties": { 3332 "registration_status": "Non-register", 3333 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3334 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3335 "customer_marketing_book_call_time": "${data["customer_marketing_book_call_time"]}", 3336 "customer_marketing_book_call_campaign": "${data["customer_marketing_book_call_campaign"]}", 3337 "form_source": "Website" 3338 ${snippetUtm} 3339 } 3340 }`; 3341 3342 jQuery.ajax({ 3343 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 3344 type: 'POST', 3345 contentType: 'application/json', 3346 data: dataCreateContact, 3347 success: function(resp) { 3348 if (callback && typeof(callback) == "function") { 3349 callback(); 3350 } 3351 } 3352 }); 3353 } 3354 } 3355 }); 3356 } 3357 3358 // track when user submit website action 3359 // simplified to exactly 2 cases: create a new contact, or update an 3360 // existing one - no "cold" contact branch here (removed 2026) 3361 this.trackSubmitWebsiteAction = function(data, callback, errorCallback) { 3362 let activeRequest; 3363 let cancelled = false; 3364 const requestHandle = { abort: function() { cancelled = true; if (activeRequest) activeRequest.abort(); } }; 3365 const dataGetContact = `{ 3366 "email": "${data["email"]}" 3367 }`; 3368 let snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 3369 3370 // firstname/lastname are optional - only forwarded when a 3371 // caller actually provides them (e.g. split from a "Full name" 3372 // form field), so existing callers that don't pass them keep 3373 // their current behavior unchanged. 3374 let firstname = (data['firstname'] || '').trim(); 3375 let lastname = (data['lastname'] || '').trim(); 3376 let nameProperties = ''; 3377 if (firstname) { 3378 nameProperties += `,\n"firstname": "${firstname}"`; 3379 } 3380 if (lastname) { 3381 nameProperties += `,\n"lastname": "${lastname}"`; 3382 } 3383 3384 // get contact 3385 activeRequest = jQuery.ajax({ 3386 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 3387 type: 'POST', 3388 contentType: 'application/json', 3389 dataType: 'json', 3390 data: dataGetContact, 3391 success: function(resp) { 3392 if (cancelled) return; 3393 //console.log(resp); 3394 if (!resp['status'] && resp['status'] !== 'error') { 3395 // contact found - update it 3396 let currentActionList = ''; 3397 if (resp['properties']['non_signup_actions']) { 3398 // already have properties 3399 currentActionList = resp['properties']['non_signup_actions']['value']; 3400 } 3401 3402 // check website action 3403 let newActionList = (currentActionList.indexOf(data['website_action']) == -1) ? currentActionList + `;${data['website_action']}` : currentActionList; 3404
3405 let dataSendToHubspot = `{ 3406 "email": "${data["email"]}", 3407 "properties": { 3408 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3409 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3410 "non_signup_actions": "${newActionList}" 3411 ${nameProperties} 3412 ${snippetUtm} 3413 } 3414 }`; 3415 3416 //console.log(dataSendToHubspot); 3417 activeRequest = jQuery.ajax({ url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/update-contact', type: 'POST', contentType: 'application/json', dataType: 'json', data: dataSendToHubspot, success: function() { if (!cancelled && callback) callback(); }, error: function() { if (!cancelled && errorCallback) errorCallback(); } }); 3418 } else { 3419 // contact not found - create a new contact 3420 let dataCreateContact = `{ 3421 "email": "${data["email"]}", 3422 "firstname": "${firstname || data["email"]}", 3423 "lastname": "${lastname || data["email"]}", 3424 "properties": { 3425 "non_signup_actions": "${data['website_action']}", 3426 "registration_status": "Non-register", 3427 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3428 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3429 "form_source": "Website" 3430 ${snippetUtm} 3431 } 3432 }`; 3433 3434 //console.log(dataCreateContact); 3435 3436 activeRequest = jQuery.ajax({ 3437 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 3438 type: 'POST', 3439 contentType: 'application/json', 3440 data: dataCreateContact, 3441 success: function(resp) { 3442 if (cancelled) return; 3443 if (callback && typeof(callback) == "function") { 3444 callback(); 3445 } 3446 }, error: function() { if (!cancelled && errorCallback) errorCallback(); } 3447 }); 3448 } 3449 }, error: function() { if (!cancelled && errorCallback) errorCallback(); } 3450 }); 3451 return requestHandle; 3452 } 3453 3454 // decodeURI throws URIError on a stray "%" (e.g. utm_campaign=50%off), fall back to the raw value 3455 this.safeDecodeURI = function(value) { 3456 try { 3457 return decodeURI(value); 3458 } catch (e) { 3459 return value; 3460 } 3461 } 3462 3463 // this function to return utm, ads click id and cookie consent properties as an object 3464 this.getUtmAndAdsClickProperties = function() { 3465 var properties = {}; 3466 var getCookie = (name) => typeof katalonCookie !== 'undefined' ? katalonCookie.getCookie(name) : null; 3467 3468 // get utm properties 3469 ['utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'utm_source'].forEach((key) => { 3470 var value = localStorage.getItem(key); 3471 if (value !== null) { 3472 properties[key] = katalonHubspot.safeDecodeURI(value); 3473 } 3474 }); 3475 3476 //get ads click id from cookie 3477 var uetRaw = getCookie("_uetmsclkid"); 3478 var msclkid = uetRaw ? uetRaw.replace(/^_uet/, "") : null; 3479 3480 var fbcRaw = getCookie("_fbc"); 3481 var fbclid = fbcRaw ? fbcRaw.split(".").slice(3).join(".") : null; 3482 3483 var liFatId = getCookie("li_fat_id"); 3484 3485 var rdtCid = getCookie("_rdt_cid"); 3486 3487 [ 3488 ['microsoft_click_id', msclkid], 3489 ['facebook_click_id', fbclid], 3490 ['linkedin_click_id', liFatId], 3491 ['reddit_click_id', rdtCid] 3492 ].forEach(([key, value]) => { 3493 if (value !== null && value !== undefined) { 3494 properties[key] = katalonHubspot.safeDecodeURI(value); 3495 } 3496 }); 3497 3498 //get cookie consent 3499 [ 3500 ['ot_strictlynecessary', 'ot_strictlyNecessary'], 3501 ['ot_performance', 'ot_performance'], 3502 ['ot_functional', 'ot_functional'], 3503 ['ot_targeting', 'ot_targeting'] 3504 ].forEach(([key, storageKey]) => { 3505 var value = localStorage.getItem(storageKey); 3506 if (value !== null) { 3507 properties[key] = value === 'true'; 3508 } 3509 }); 3510 3511 // delete utm 3512 localStorage.removeItem("utm_medium"); 3513 localStorage.removeItem("utm_campaign"); 3514 localStorage.removeItem("utm_content"); 3515 localStorage.removeItem("utm_term"); 3516 localStorage.removeItem("utm_source"); 3517 3518 return properties; 3519 } 3520 3521 // this function to return snippetUtm, a JSON fragment appended into hand-built payloads 3522 this.getUtmAndAdsClickSnippet = function() { 3523 var properties = katalonHubspot.getUtmAndAdsClickProperties(); 3524 3525 return Object.keys(properties).map((key) => `,\n"${key}": ${JSON.stringify(properties[key])}`).join(''); 3526 } 3527 3528 // this function to check overridable leadsource - update 20260720 3529 this.isOverridableLeadsource = function(data, newLeadSource) { 3530 const highIntentList = ['Talk to Sales', 'View A Demo', 'High Intent - MKT Conference', 'High Intent - MKT Webinar', 'Website Chatbot']; 3531 const salesOwnedStatusList = ['Working', 'Nurturing', 'Qualified', 'Book a Call', 'Paid User']; 3532 3533 let currentLeadsource = data['leadsource'] ? data['leadsource']['value'] : ''; 3534 3535 if (!highIntentList.includes(currentLeadsource)) { 3536 return true; 3537 } 3538 3539 // current leadsource is high intent: a non-high-intent new source can never override it 3540 if (!highIntentList.includes(newLeadSource)) { 3541 return false;
3542 } 3543 3544 // both current and new leadsource are high intent: only allow override when the contact 3545 // is NOT in the "MQL or PQL less than 90 days" segment (i.e. MQL/PQL is empty or > 90 days) 3546 // AND sales is not already working/nurturing/qualifying it (a lead with no status yet doesn't gate this) 3547 let mqlTimestamp = data['days_since_from_mql'] ? data['days_since_from_mql']['value'] : ''; 3548 let pqlTimestamp = data['days_since_from_pql'] ? data['days_since_from_pql']['value'] : ''; 3549 let daysFromMql = mqlTimestamp === '' ? Infinity : (Date.now() - parseInt(mqlTimestamp)) / (1000 * 60 * 60 * 24); 3550 let daysFromPql = pqlTimestamp === '' ? Infinity : (Date.now() - parseInt(pqlTimestamp)) / (1000 * 60 * 60 * 24); 3551 let currentLeadStatus = data['lead_status'] ? data['lead_status']['value'] : ''; 3552 3553 return daysFromMql > 90 && daysFromPql > 90 && !salesOwnedStatusList.includes(currentLeadStatus); 3554 } 3555 3556 // this function to check overridable leadsource for cold 3557 this.isOverridableLeadsourceForCold = function(data, newLeadSource) { 3558 const notOverrideList = ['Support Portal', 'Business Email', 'Request Custom Demo', 'Talk to Sales', 'View A Demo', 'Partner', 'Partner Event', 'High Intent - MKT Conference', 'High Intent - MKT Webinar']; 3559 const highIntentList = ['Request Custom Demo', 'Talk to Sales', 'View A Demo', 'High Intent - MKT Conference', 'High Intent - MKT Webinar']; 3560 // update Mar 19, 2024 3561 // update function logic 3562 let currentLeadsource = data['leadsource_2nd'] ? data['leadsource_2nd']['value'] : ''; 3563 let currentLeadsourceByCampaign = data['leadsource_by_campaign_2nd'] ? data['leadsource_by_campaign_2nd']['value'] : ''; 3564 let bookCalendarStatus = data['book_calendar_meeting_status__cold_'] && data['book_calendar_meeting_status__cold_']['value'] == 'true' ? true : false; 3565 let coldEffectStatus = data['cold_unqualified_scoring_effect_status'] && data['cold_unqualified_scoring_effect_status']['value'] == 'true' ? true : false; // have apply cold effect 3566 3567 if (coldEffectStatus) { 3568 // only override for cold/unqualified 3569 if (!currentLeadsource || currentLeadsource == '') { 3570 // don't have leadsource 2nd or leadsource = empty 3571 return true; 3572 } else if ( 3573 highIntentList.includes(newLeadSource) && 3574 !notOverrideList.includes(currentLeadsource) && 3575 currentLeadsourceByCampaign != 'Trial Drip Email' && 3576 !bookCalendarStatus 3577 ) { 3578 // just override by high intent leadsource 3579 // and current leadsource isn't high intent 3580 // havent book calendar yet 3581 return true; 3582 } else { 3583 return false; 3584 } 3585 } 3586 // dont have permission to apply cold 3587 return false; 3588 } 3589 3590 this.trackSubmitOnboardingHubMessage = function(data, callback) { 3591 var dataGetContact = `{ 3592 "email": "${data["email"]}" 3593 }`; 3594 3595 // format first and last name 3596 data["fullname"] = data["fullname"].toLowerCase(); 3597 var fullname = data["fullname"].trim().split(/\s+/).filter(Boolean).map((word) => { 3598 return word[0].toUpperCase() + word.substring(1); 3599 }); 3600 var firstname = fullname.slice(0, -1).join(" "); 3601 var lastname = fullname[fullname.length - 1]; 3602 3603 // get contact 3604 jQuery.ajax({ 3605 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 3606 type: 'POST', 3607 contentType: 'application/json', 3608 dataType: 'json', 3609 data: dataGetContact, 3610 success: function(resp) { 3611 //console.log(resp); 3612 if (!resp['status'] && resp['status'] !== 'error') { 3613 // have contact 3614 3615 var dataSendToHubspot = `{ 3616 "email": "${data["email"]}", 3617 "properties": { 3618 "firstname": "${firstname}", 3619 "lastname": "${lastname}", 3620 "cs_onboarding_hub_question": "${data["cs_onboarding_hub_question"]}" 3621 } 3622 }`; 3623 3624 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 3625 } else { 3626 // contact not exist 3627 3628 // create a new contact 3629 var dataCreateContact = `{ 3630 "email": "${data["email"]}", 3631 "firstname": "${firstname}", 3632 "lastname": "${lastname}", 3633 "properties": { 3634 "cs_onboarding_hub_question": "${data["cs_onboarding_hub_question"]}" 3635 } 3636 }`; 3637 3638 //console.log(dataCreateContact); 3639 3640 jQuery.ajax({ 3641 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 3642 type: 'POST', 3643 contentType: 'application/json', 3644 data: dataCreateContact, 3645 success: function(resp) { 3646 if (callback && typeof(callback) == "function") { 3647 callback(); 3648 } 3649 } 3650 }); 3651 } 3652 3653 } 3654 }); 3655 } 3656 3657 this.trackSubmitSOQR24WaitList = function(data, callback) { 3658 var dataGetContact = `{ 3659 "email": "${data["email"]}" 3660 }`; 3661 3662 // get contact 3663 jQuery.ajax({ 3664 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 3665 type: 'POST', 3666 contentType: 'application/json', 3667 dataType: 'json', 3668 data: dataGetContact, 3669 success: function(resp) { 3670 //console.log(resp); 3671 if (!resp['status'] && resp['status'] !== 'error') { 3672 // have contact 3673 3674 var dataSendToHubspot = `{ 3675 "email": "${data["email"]}", 3676 "properties": { 3677 "soqr24___wait_list": "true" 3678 } 3679 }`; 3680 3681 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 3682 } else { 3683 // contact not exist 3684 3685 // create a new contact 3686 var dataCreateContact = `{ 3687 "email": "${data["email"]}", 3688 "firstname": "${data["email"]}", 3689 "lastname": "", 3690 "properties": { 3691 "soqr24___wait_list": "true" 3692 } 3693 }`; 3694 3695 jQuery.ajax({ 3696 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 3697 type: 'POST', 3698 contentType: 'application/json', 3699 data: dataCreateContact, 3700 success: function(resp) { 3701 if (callback && typeof(callback) == "function") { 3702 callback(); 3703 } 3704 } 3705 }); 3706 } 3707 3708 } 3709 }); 3710 } 3711 3712 // function tracking submit SOQR24 report download form 3713 this.trackSubmitDownloadSOQR24Report = function(data, callback) { 3714 var dataGetContact = `{ 3715 "email": "${data["email"]}" 3716 }`; 3717 3718 // format first and last name 3719 data["fullname"] = data["fullname"].toLowerCase(); 3720 var fullname = data["fullname"].trim().split(/\s+/).filter(
3720Boolean).map((word) => { 3721 return word[0].toUpperCase() + word.substring(1); 3722 }); 3723 var firstname = fullname.slice(0, -1).join(" "); 3724 var lastname = fullname[fullname.length - 1]; 3725 3726 // get time now 3727 var timeSubmit = Date.now(); 3728 3729 // get utm properties 3730 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 3731 3732 // get contact 3733 jQuery.ajax({ 3734 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 3735 type: 'POST', 3736 contentType: 'application/json', 3737 dataType: 'json', 3738 data: dataGetContact, 3739 success: function(resp) { 3740 //console.log(resp); 3741 var currentActionList = ''; 3742 if (!resp['status'] && resp['status'] !== 'error') { 3743 // have contact 3744 // update properties into this contact 3745 if (resp['properties']['non_signup_actions']) { 3746 // already have properties 3747 currentActionList = resp['properties']['non_signup_actions']['value']; 3748 } 3749 3750 // check website action 3751 let newActionList = (currentActionList.indexOf(data['website_action']) == -1) ? currentActionList + `${data['website_action']}` : currentActionList; 3752 var dataSendToHubspot = `{ 3753 "email": "${data["email"]}", 3754 "properties": { 3755 "firstname": "${firstname}", 3756 "lastname": "${lastname}", 3757 "jobtitle": "${data["job_title"]}", 3758 "soqr2024_submit_timestamp": "${timeSubmit}", 3759 "which_stage_of_test_automation_best_describes_your_current_progress_": "${data["which_stage_of_test_automation_best_describes_your_current_progress_"] || ""}", 3760 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3761 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}" 3762 ${snippetUtm} 3763 } 3764 }`; 3765 3766 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 3767 } else { 3768 // contact not exist 3769 3770 // create a new contact 3771 var dataCreateContact = `{ 3772 "email": "${data["email"]}", 3773 "firstname": "${firstname}", 3774 "lastname": "${lastname}", 3775 "properties": { 3776 "jobtitle": "${data["job_title"]}", 3777 "which_stage_of_test_automation_best_describes_your_current_progress_": "${data["which_stage_of_test_automation_best_describes_your_current_progress_"] || ""}", 3778 "soqr2024_submit_timestamp": "${timeSubmit}", 3779 "registration_status": "Non-register", 3780 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3781 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3782 "form_source": "Website" 3783 ${snippetUtm} 3784 } 3785 }`; 3786 3787 //console.log(dataCreateContact); 3788 3789 jQuery.ajax({ 3790 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 3791 type: 'POST', 3792 contentType: 'application/json', 3793 data: dataCreateContact, 3794 success: function(resp) { 3795 if (callback && typeof(callback) == "function") { 3796 callback(); 3797 } 3798 } 3799 }); 3800 } 3801 3802 } 3803 }); 3804 } 3805 3806 // function tracking submit EuroStar 2024 Event 3807 this.trackSubmitEuroStarEvent = function(data, callback) { 3808 var dataGetContact = `{ 3809 "email": "${data["email"]}" 3810 }`; 3811 3812 // format first and last name 3813 const fullname = []; 3814 3815 data["fullname"].toLowerCase().trim().split(/\s+/).filter(
3815Boolean).map((word) => { 3816 fullname.push(word[0].toUpperCase() + word.substring(1)); 3817 }); 3818 3819 let firstname = ""; 3820 let lastname = ""; 3821 3822 fullname.map((name, index) => { 3823 if (index === 0) { 3824 firstname = name; 3825 } 3826 else if (index + 1 === fullname.length) { 3827 lastname += name; 3828 } 3829 else { 3830 lastname += name + " "; 3831 } 3832 }); 3833 3834 // get time now 3835 var timeSubmit = Date.now(); 3836 3837 // get utm properties 3838 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 3839 3840 // get contact 3841 jQuery.ajax({ 3842 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 3843 type: 'POST', 3844 contentType: 'application/json', 3845 dataType: 'json', 3846 data: dataGetContact, 3847 success: function(resp) { 3848 if (!resp['status'] && resp['status'] !== 'error') { 3849 // have contact 3850 var dataSendToHubspot = `{ 3851 "email": "${data["email"]}", 3852 "properties": { 3853 "firstname": "${firstname}", 3854 "lastname": "${lastname}", 3855 "jobtitle": "${data["jobtitle"] ?? ''}", 3856 "company_name_input_by_user": "${data["company_name_input_by_user"] ?? ''}", 3857 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 3858 "eurostar_timeslot": "${data["eurostar_timeslot"] ?? 'Other (please specify)'}", 3859 "eurostar_timeslot_other": "${data["eurostar_timeslot_other"] ?? ''}", 3860 "eurostar_note": "${data["eurostar_note"] ?? ''}", 3861 "eurostar_submit_timestamp": "${timeSubmit}", 3862 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3863 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}" 3864 ${snippetUtm} 3865 } 3866 }`; 3867 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 3868 } else { 3869 // don't have contact 3870 // create new contact with leadsource 3871 var dataCreateContact = `{ 3872 "email": "${data["email"]}", 3873 "firstname": "${firstname}", 3874 "lastname": "${lastname}", 3875 "properties": { 3876 "jobtitle": "${data["jobtitle"] ?? ''}", 3877 "company_name_input_by_user": "${data["company_name_input_by_user"] ?? ''}", 3878 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 3879 "eurostar_timeslot": "${data["eurostar_timeslot"] ?? 'Other (please specify)'}", 3880 "eurostar_timeslot_other": "${data["eurostar_timeslot_other"] ?? ''}", 3881 "eurostar_note": "${data["eurostar_note"] ?? ''}", 3882 "registration_status": "Non-register", 3883 "form_source": "Website", 3884 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3885 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 3886 "eurostar_submit_timestamp": "${timeSubmit}" 3887 ${snippetUtm} 3888 } 3889 }`; 3890 3891 jQuery.ajax({ 3892 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 3893 type: 'POST', 3894 contentType: 'application/json', 3895 data: dataCreateContact, 3896 success: function(resp) { 3897 if (callback && typeof(callback) == "function") { 3898 callback(); 3899 } 3900 } 3901 }); 3902 } 3903 3904 } 3905 }); 3906 } 3907 3908 // function tracking submit offline event 3909 this.trackSubmitOfflineEventMeetingRequest = function(data, callback) { 3910 var dataGetContact = `{ 3911 "email": "${data["email"]}" 3912 }`; 3913 3914 // format first and last name 3915 const fullname = []; 3916 3917 data["fullname"].toLowerCase().trim().split(/\s+/).filter(
3917Boolean).map((word) => { 3918 fullname.push(word[0].toUpperCase() + word.substring(1)); 3919 }); 3920 3921 let firstname = ""; 3922 let lastname = ""; 3923 3924 fullname.map((name, index) => { 3925 if (index === 0) { 3926 firstname = name; 3927 } 3928 else if (index + 1 === fullname.length) { 3929 lastname += name; 3930 } 3931 else { 3932 lastname += name + " "; 3933 } 3934 }); 3935 3936 // get time now 3937 var timeSubmit = Date.now(); 3938 3939 // get utm properties 3940 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 3941 3942 // get contact 3943 jQuery.ajax({ 3944 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 3945 type: 'POST', 3946 contentType: 'application/json', 3947 dataType: 'json', 3948 data: dataGetContact, 3949 success: function(resp) { 3950 if (!resp['status'] && resp['status'] !== 'error') { 3951 let snippetEventTrackingName = ''; 3952 if (data['event_tracking_name']) { 3953 snippetEventTrackingName = `,"${data['event_tracking_name']}": "${timeSubmit}"` 3954 } 3955 // have contact 3956 var dataSendToHubspot = `{ 3957 "email": "${data["email"]}", 3958 "properties": { 3959 "firstname": "${firstname}", 3960 "lastname": "${lastname}", 3961 "jobtitle": "${data["jobtitle"] ?? ''}", 3962 "company_name_input_by_user": "${data["company_name_input_by_user"] ?? ''}", 3963 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 3964 "event_notes": "${data["event_notes"] ?? ''}", 3965 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3966 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}" 3967 ${snippetEventTrackingName} 3968 ${snippetUtm} 3969 } 3970 }`; 3971 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 3972 } else { 3973 let snippetEventTrackingName = ''; 3974 if (data['event_tracking_name']) { 3975 snippetEventTrackingName = `,"${data['event_tracking_name']}": "${timeSubmit}"` 3976 } 3977 // don't have contact 3978 var dataCreateContact = `{ 3979 "email": "${data["email"]}", 3980 "firstname": "${firstname}", 3981 "lastname": "${lastname}", 3982 "properties": { 3983 "jobtitle": "${data["jobtitle"] ?? ''}", 3984 "company_name_input_by_user": "${data["company_name_input_by_user"] ?? ''}", 3985 "custom_phone_number": "${data["custom_phone_number"] ?? ''}", 3986 "event_notes": "${data["event_notes"] ?? ''}", 3987 "registration_status": "Non-register", 3988 "form_source": "Website", 3989 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 3990 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}" 3991 ${snippetEventTrackingName} 3992 ${snippetUtm} 3993 } 3994 }`; 3995 3996 jQuery.ajax({ 3997 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 3998 type: 'POST', 3999 contentType: 'application/json', 4000 data: dataCreateContact, 4001 success: function(resp) { 4002 if (callback && typeof(callback) == "function") { 4003 callback(); 4004 } 4005 } 4006 }); 4007 } 4008 4009 } 4010 }); 4011 } 4012 4013 // track when user submit PF Capturing Form 4014 this.trackSubmitPFCapturingForm = function(data, callback) { 4015 var dataGetContact = `{ 4016 "email": "${data["email"]}" 4017 }`; 4018 4019 // format first and last name 4020 const fullname = []; 4021 4022 data["fullname"].toLowerCase().trim().split(/\s+/).filter(
4022Boolean).map((word) => { 4023 fullname.push(word[0].toUpperCase() + word.substring(1)); 4024 }); 4025 4026 let firstname = ""; 4027 let lastname = ""; 4028 4029 fullname.map((name, index) => { 4030 if (index === 0) { 4031 firstname = name; 4032 } 4033 else if (index + 1 === fullname.length) { 4034 lastname += name; 4035 } 4036 else { 4037 lastname += name + " "; 4038 } 4039 }); 4040 4041 // get time now 4042 var timeSubmit = Date.now(); 4043 4044 // get utm properties 4045 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 4046 4047 // get contact 4048 jQuery.ajax({ 4049 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 4050 type: 'POST', 4051 contentType: 'application/json', 4052 dataType: 'json', 4053 data: dataGetContact, 4054 success: function(resp) { 4055 if (!resp['status'] && resp['status'] !== 'error') { 4056 // have contact 4057 let dataSendToHubspot = `{ 4058 "email": "${data["email"]}", 4059 "properties": { 4060 "firstname": "${firstname}", 4061 "lastname": "${lastname}", 4062 "jobtitle": "${data["jobtitle"] ?? ''}", 4063 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 4064 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 4065 "pf_capturing_form_submitted_timestamp": "${timeSubmit}" 4066 ${snippetUtm} 4067 } 4068 }`; 4069 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 4070 } else { 4071 // don't have contact 4072 // create new contact with leadsource 4073 var dataCreateContact = `{ 4074 "email": "${data["email"]}", 4075 "firstname": "${firstname}", 4076 "lastname": "${lastname}", 4077 "properties": { 4078 "jobtitle": "${data["jobtitle"] ?? ''}", 4079 "registration_status": "Non-register", 4080 "form_source": "Website", 4081 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 4082 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 4083 "pf_capturing_form_submitted_timestamp": "${timeSubmit}" 4084 ${snippetUtm} 4085 } 4086 }`; 4087 4088 jQuery.ajax({ 4089 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 4090 type: 'POST', 4091 contentType: 'application/json', 4092 data: dataCreateContact, 4093 success: function(resp) { 4094 if (callback && typeof(callback) == "function") { 4095 callback(); 4096 } 4097 } 4098 }); 4099 } 4100 4101 } 4102 }); 4103 } 4104 4105 //Reserve 1K Promote Form Submit 4106 this.trackSubmitReserve1KPromote = function(data, callback) { 4107 var dataGetContact = `{ 4108 "email": "${data["email"]}" 4109 }`; 4110 4111 // get time now 4112 var selfserve_promotion_campaign_reserve_timestamp = Date.now(); 4113 4114 // get utm properties 4115 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 4116 4117 // get contact 4118 jQuery.ajax({ 4119 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 4120 type: 'POST', 4121 contentType: 'application/json', 4122 dataType: 'json', 4123 data: dataGetContact, 4124 success: function(resp) { 4125 //console.log(resp); 4126 if (!resp['status'] && resp['status'] !== 'error') { 4127 // have contact 4128 // update properties into this contact 4129 var dataSendToHubspot = `{ 4130 "email": "${data["email"]}", 4131 "properties": { 4132 "selfserve_promotion_campaign_reserve_timestamp": "${selfserve_promotion_campaign_reserve_timestamp}" 4133 ${snippetUtm} 4134 } 4135 }`; 4136 4137 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 4138 } else { 4139 // contact not exist 4140 4141 // create a new contact 4142 var dataCreateContact = `{ 4143 "email": "${data["email"]}", 4144 "firstname": "${data["email"]}", 4145 "lastname": "${data["email"]}", 4146 "properties": { 4147 "registration_status": "Non-register", 4148 "selfserve_promotion_campaign_reserve_timestamp": "${selfserve_promotion_campaign_reserve_timestamp}", 4149 "form_source": "Website" 4150 ${snippetUtm} 4151 } 4152 }`; 4153 4154 //console.log(dataCreateContact); 4155 4156 jQuery.ajax({ 4157 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 4158 type: 'POST', 4159 contentType: 'application/json', 4160 data: dataCreateContact, 4161 success: function(resp) { 4162 if (callback && typeof(callback) == "function") { 4163 callback(); 4164 } 4165 } 4166 }); 4167 } 4168 4169 } 4170 }); 4171 } 4172 4173 //SOQR25 Teasing Form Submit 4174 this.trackSubmitSOQR25TeasingForm = function(data, callback) { 4175 var dataGetContact = `{ 4176 "email": "${data["email"]}" 4177 }`; 4178 4179 // format first and last name 4180 const fullname = []; 4181 4182 data["fullname"].toLowerCase().trim().split(/\s+/).filter(
4182Boolean).map((word) => { 4183 fullname.push(word[0].toUpperCase() + word.substring(1)); 4184 }); 4185 4186 let firstname = ""; 4187 let lastname = ""; 4188 4189 fullname.map((name, index) => { 4190 if (index === 0) { 4191 firstname = name; 4192 } 4193 else if (index + 1 === fullname.length) { 4194 lastname += name; 4195 } 4196 else { 4197 lastname += name + " "; 4198 } 4199 }); 4200 4201 // get utm properties 4202 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 4203 4204 const timeSubmit = Date.now(); 4205 4206 // get contact 4207 jQuery.ajax({ 4208 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 4209 type: 'POST', 4210 contentType: 'application/json', 4211 dataType: 'json', 4212 data: dataGetContact, 4213 success: function(resp) { 4214 //console.log(resp); 4215 let currentActionList = ''; 4216 if (!resp['status'] && resp['status'] !== 'error') { 4217 // have contact 4218 // update properties into this contact 4219 if (resp['properties']['non_signup_actions']) { 4220 // already have properties 4221 currentActionList = resp['properties']['non_signup_actions']['value']; 4222 } 4223 4224 // check website action 4225 let newActionList = (currentActionList.indexOf(data['website_action']) == -1) ? currentActionList + `;${data['website_action']}` : currentActionList; 4226 4227 let dataSendToHubspot = `{ 4228 "email": "${data["email"]}", 4229 "properties": { 4230 "firstname": "${firstname}", 4231 "lastname": "${lastname}", 4232 "non_signup_actions": "${newActionList}", 4233 "soqr25_submit_timestamp": "${timeSubmit}", 4234 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 4235 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}" 4236 ${snippetUtm} 4237 } 4238 }`; 4239 4240 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 4241 4242 // send for cold 4243 // action after cold 4244 let currentActionColdList = ''; 4245 if (resp['properties']['website_actions_after_cold']) { 4246 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 4247 } 4248 let newActionColdList = (currentActionColdList.indexOf(data['website_action']) == -1) ? currentActionColdList + `;${data['website_action']}` : currentActionColdList; 4249 let coldActionData = ''; 4250 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 4251 // call api update for cold lead only 4252 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`; 4253 let dataColdSendToHubspot = `{ 4254 "email": "${data["email"]}", 4255 "properties": { 4256 ${coldActionData} 4257 } 4258 }`; 4259 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 4260 } 4261 } else { 4262 // contact not exist 4263 // create a new contact 4264 var dataCreateContact = `{ 4265 "email": "${data["email"]}", 4266 "firstname": "${firstname}", 4267 "lastname": "${lastname}", 4268 "properties": { 4269 "non_signup_actions": "${data['website_action']}", 4270 "soqr25_submit_timestamp": "${timeSubmit}", 4271 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 4272 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 4273 "registration_status": "Non-register", 4274 "form_source": "Website" 4275 ${snippetUtm} 4276 } 4277 }`; 4278 4279 jQuery.ajax({ 4280 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 4281 type: 'POST', 4282 contentType: 'application/json', 4283 data: dataCreateContact, 4284 success: function(resp) { 4285 if (callback && typeof(callback) == "function") { 4286 callback(); 4287 } 4288 } 4289 }); 4290 } 4291 4292 } 4293 }); 4294 } 4295 4296 //Quality Horizon Webinar Form Submit 4297 this.trackSubmiQualitytHorizonWebinarForm = function(data, callback) { 4298 var dataGetContact = `{ 4299 "email": "${data["email"]}" 4300 }`; 4301 4302 // get utm properties 4303 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 4304 4305 // get contact 4306 jQuery.ajax({ 4307 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 4308 type: 'POST', 4309 contentType: 'application/json', 4310 dataType: 'json', 4311 data: dataGetContact, 4312 success: function(resp) { 4313 //console.log(resp); 4314 let currentActionList = ''; 4315 if (!resp['status'] && resp['status'] !== 'error') { 4316 // have contact 4317 // update properties into this contact 4318 if (resp['properties']['non_signup_actions']) { 4319 // already have properties 4320 currentActionList = resp['properties']['non_signup_actions']['value']; 4321 } 4322 4323 // check website action 4324 let newActionList = (currentActionList.indexOf(data['webinar_name']) == -1) ? currentActionList + `;${data['webinar_name']}` : currentActionList; 4325
4326 let dataSendToHubspot = `{ 4327 "email": "${data["email"]}", 4328 "properties": { 4329 "jobtitle": "${data["job_title"]}", 4330 "non_signup_actions": "${newActionList}", 4331 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 4332 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}" 4333 ${snippetUtm} 4334 } 4335 }`; 4336 4337 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 4338 4339 // send for cold 4340 // action after cold 4341 let currentActionColdList = ''; 4342 if (resp['properties']['website_actions_after_cold']) { 4343 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 4344 } 4345 let newActionColdList = (currentActionColdList.indexOf(data['webinar_name']) == -1) ? currentActionColdList + `;${data['webinar_name']}` : currentActionColdList; 4346 let coldActionData = ''; 4347 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 4348 // call api update for cold lead only 4349 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`; 4350 let dataColdSendToHubspot = `{ 4351 "email": "${data["email"]}", 4352 "properties": { 4353 ${coldActionData} 4354 } 4355 }`; 4356 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 4357 } 4358 } else { 4359 // contact not exist 4360 // create a new contact 4361 var dataCreateContact = `{ 4362 "email": "${data["email"]}", 4363 "firstname": "", 4364 "lastname": "", 4365 "properties": { 4366 "non_signup_actions": "${data['webinar_name']}", 4367 "jobtitle": "${data["job_title"]}", 4368 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 4369 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 4370 "registration_status": "Non-register", 4371 "form_source": "Website" 4372 ${snippetUtm} 4373 } 4374 }`; 4375 4376 jQuery.ajax({ 4377 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 4378 type: 'POST', 4379 contentType: 'application/json', 4380 data: dataCreateContact, 4381 success: function(resp) { 4382 if (callback && typeof(callback) == "function") { 4383 callback(); 4384 } 4385 } 4386 }); 4387 } 4388 4389 } 4390 }); 4391 } 4392 4393 //ROI Calculator Download Form Submit 4394 this.trackSubmitROIDownloadForm = function(data, callback) { 4395 var dataGetContact = `{ 4396 "email": "${data["email"]}" 4397 }`; 4398 4399 // get utm properties 4400 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 4401 4402 const timeSubmit = Date.now(); 4403 4404 // get contact 4405 jQuery.ajax({ 4406 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 4407 type: 'POST', 4408 contentType: 'application/json', 4409 dataType: 'json', 4410 data: dataGetContact, 4411 success: function(resp) { 4412 let currentActionList = ''; 4413 if (!resp['status'] && resp['status'] !== 'error') { 4414 // have contact 4415 // update properties into this contact 4416 if (resp['properties']['non_signup_actions']) { 4417 // already have properties 4418 currentActionList = resp['properties']['non_signup_actions']['value']; 4419 } 4420 4421 // check website action 4422 let newActionList = (currentActionList.indexOf(data['website_action']) == -1) ? currentActionList + `;${data['website_action']}` : currentActionList; 4423
4424 let dataSendToHubspot = `{ 4425 "email": "${data["email"]}", 4426 "properties": { 4427 "non_signup_actions": "${newActionList}", 4428 ${data["roi_like_to_talk_to_katalon_experts"] ? `"leadsource": "${data["leadsource"]}","leadsource_by_campaign": "${data["leadsource_by_campaign"]}"` : ""} 4429 "roi_like_to_talk_to_katalon_experts": "${data["roi_like_to_talk_to_katalon_experts"]}", 4430 "roi_download_pdf_submit_timestamp": "${timeSubmit}", 4431 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 4432 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}" 4433 ${snippetUtm} 4434 } 4435 }`; 4436 4437 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 4438 4439 // send for cold 4440 // action after cold 4441 let currentActionColdList = ''; 4442 if (resp['properties']['website_actions_after_cold']) { 4443 currentActionColdList = resp['properties']['website_actions_after_cold']['value']; 4444 } 4445 let newActionColdList = (currentActionColdList.indexOf(data['website_action']) == -1) ? currentActionColdList + `;${data['website_action']}` : currentActionColdList; 4446 let coldActionData = ''; 4447 if (resp['properties']['cold_unqualified_scoring_effect_status'] && resp['properties']['cold_unqualified_scoring_effect_status']['value'] == 'true') { 4448 // call api update for cold lead only 4449 coldActionData = `"website_actions_after_cold": "${newActionColdList}"`; 4450 let dataColdSendToHubspot = `{ 4451 "email": "${data["email"]}", 4452 "properties": { 4453 ${coldActionData} 4454 } 4455 }`; 4456 katalonHubspot.sendToHubspot(dataColdSendToHubspot); 4457 } 4458 } else { 4459 // contact not exist 4460 // create a new contact 4461 var dataCreateContact = `{ 4462 "email": "${data["email"]}", 4463 "firstname": "${data["email"]}", 4464 "lastname": "${data["email"]}", 4465 "properties": { 4466 "non_signup_actions": "${data['website_action']}", 4467 ${data["roi_like_to_talk_to_katalon_experts"] ? `"leadsource": "${data["leadsource"]}","leadsource_by_campaign": "${data["leadsource_by_campaign"]}",` : ""} 4468 "roi_like_to_talk_to_katalon_experts": "${data["roi_like_to_talk_to_katalon_experts"]}", 4469 "roi_download_pdf_submit_timestamp": "${timeSubmit}", 4470 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 4471 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}", 4472 "registration_status": "Non-register", 4473 "form_source": "Website" 4474 ${snippetUtm} 4475 } 4476 }`; 4477 4478 jQuery.ajax({ 4479 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 4480 type: 'POST', 4481 contentType: 'application/json', 4482 data: dataCreateContact, 4483 success: function(resp) { 4484 if (callback && typeof(callback) == "function") { 4485 callback(); 4486 } 4487 } 4488 }); 4489 } 4490 4491 } 4492 }); 4493 } 4494 4495 // Submit HS token for Chatbot 4496 this.submitHubspotutkForChatbot = function(data, callback) { 4497 let submitData = { 4498 submittedAt: Date.now(), 4499 fields: [ 4500 { 4501 objectTypeId: "0-1", 4502 name: "email", 4503 value: data.email 4504 } 4505 ], 4506 context: { 4507 hutk: data.hubspotutk 4508 } 4509 } 4510 4511 jQuery.ajax({ 4512 url: 'https://api.hsforms.com/submissions/v3/integration/submit/2465122/dc3b2424-b7b9-4c06-9cdc-39dd4994bcae', 4513 type: 'POST', 4514 data: JSON.stringify(submitData), 4515 headers: { 4516 'Content-Type': 'application/json' 4517 }, 4518 success: function(resp) { 4519 if (callback && typeof(callback) == "function") { 4520 callback(); 4521 } 4522 } 4523 }); 4524 } 4525 4526 this.trackSubmitStarEast2025 = function(data, callback) { 4527 var dataGetContact = `{ 4528 "email": "${data["email"]}" 4529 }`; 4530 4531 // format first and last name 4532 const fullname = []; 4533 4534 data["fullname"].toLowerCase().trim().split(/\s+/).filter(
4534Boolean).map((word) => { 4535 fullname.push(word[0].toUpperCase() + word.substring(1)); 4536 }); 4537 4538 let firstname = ""; 4539 let lastname = ""; 4540 4541 fullname.map((name, index) => { 4542 if (index === 0) { 4543 firstname = name; 4544 } 4545 else if (index + 1 === fullname.length) { 4546 lastname += name; 4547 } 4548 else { 4549 lastname += name + " "; 4550 } 4551 }); 4552 4553 // get time now 4554 var timeSubmit = Date.now(); 4555 4556 // get utm properties 4557 var snippetUtm = katalonHubspot.getUtmAndAdsClickSnippet(); 4558 4559 // get contact 4560 jQuery.ajax({ 4561 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 4562 type: 'POST', 4563 contentType: 'application/json', 4564 dataType: 'json', 4565 data: dataGetContact, 4566 success: function(resp) { 4567 if (!resp['status'] && resp['status'] !== 'error') { 4568 // have contact 4569 var dataSendToHubspot = `{ 4570 "email": "${data["email"]}", 4571 "properties": { 4572 "firstname": "${firstname}", 4573 "lastname": "${lastname}", 4574 "jobtitle": "${data["jobtitle"] ?? ''}", 4575 "company_name_input_by_user": "${data["company"] ?? ''}", 4576 "stareast_lego_display_name": "${data["stareast_lego_display_name"] ?? ''}", 4577 "stareast_deliver_address": "${data["stareast_deliver_address"] ?? ''}", 4578 "stareast_2025_submit_timestamp": "${timeSubmit}", 4579 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 4580 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}" 4581 ${snippetUtm} 4582 } 4583 }`; 4584 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 4585 } else { 4586 // don't have contact 4587 // create new contact with leadsource 4588 var dataCreateContact = `{ 4589 "email": "${data["email"]}", 4590 "firstname": "${firstname}", 4591 "lastname": "${lastname}", 4592 "properties": { 4593 "jobtitle": "${data["jobtitle"] ?? ''}", 4594 "company_name_input_by_user": "${data["company"] ?? ''}", 4595 "stareast_lego_display_name": "${data["stareast_lego_display_name"] ?? ''}", 4596 "stareast_deliver_address": "${data["stareast_deliver_address"] ?? ''}", 4597 "stareast_2025_submit_timestamp": "${timeSubmit}", 4598 "registration_status": "Non-register", 4599 "form_source": "Website", 4600 "usebouncer_email_status": "${data["usebouncer_email_status"]}", 4601 "usebouncer_domain_type": "${data["usebouncer_domain_type"]}" 4602 ${snippetUtm} 4603 } 4604 }`; 4605 4606 jQuery.ajax({ 4607 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 4608 type: 'POST', 4609 contentType: 'application/json', 4610 data: dataCreateContact, 4611 success: function(resp) { 4612 if (callback && typeof(callback) == "function") { 4613 callback(); 4614 } 4615 } 4616 }); 4617 } 4618 4619 } 4620 }); 4621 } 4622 4623 //Simple Product Listing Form Submit 4624 this.trackSubmitSimpleProductListingForm = function(data, callback) { 4625 var dataGetContact = `{ 4626 "email": "${data["email"]}" 4627 }`; 4628 4629 // format first and last name 4630 const fullname = []; 4631 4632 data["fullname"].toLowerCase().trim().split(/\s+/).filter(
4632Boolean).map((word) => { 4633 fullname.push(word[0].toUpperCase() + word.substring(1)); 4634 }); 4635 4636 let firstname = ""; 4637 let lastname = ""; 4638 4639 fullname.map((name, index) => { 4640 if (index === 0) { 4641 firstname = name; 4642 } 4643 else if (index + 1 === fullname.length) { 4644 lastname += name; 4645 } 4646 else { 4647 lastname += name + " "; 4648 } 4649 }); 4650 const receiveNews = data["receiveNews"] || ""; 4651 4652 var pricingCheckoutUrl = encodeURIComponent(data["pricing_checkout_url"]) || ""; 4653 4654 // get time now 4655 var timeSubmit = Date.now(); 4656 4657 // get contact 4658 jQuery.ajax({ 4659 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/get-contact', 4660 type: 'POST', 4661 contentType: 'application/json', 4662 dataType: 'json', 4663 data: dataGetContact, 4664 success: function(resp) { 4665 //console.log(resp); 4666 let currentActionList = ''; 4667 if (!resp['status'] && resp['status'] !== 'error') { 4668 // have contact 4669 // update properties into this contact 4670 if (resp['properties']['non_signup_actions']) { 4671 // already have properties 4672 currentActionList = resp['properties']['non_signup_actions']['value']; 4673 } 4674 4675 // check website action 4676 let newActionList = (currentActionList.indexOf(data['website_action']) == -1) ? currentActionList + `;${data['website_action']}` : currentActionList; 4677 4678 let dataSendToHubspot = `{ 4679 "email": "${data["email"]}", 4680 "properties": { 4681 "firstname": "${firstname}", 4682 "lastname": "${lastname}", 4683 ${receiveNews ? `"i_agree_to_receive_news___marketing_updates_": "${receiveNews}",` : ""} 4684 "non_signup_actions": "${newActionList}", 4685 "pricing_checkout_url": "${pricingCheckoutUrl}", 4686 "simple_product_listing_checkout_timestamp": "${timeSubmit}" 4687 } 4688 }`; 4689 4690 katalonHubspot.sendToHubspot(dataSendToHubspot, callback); 4691 } else { 4692 // contact not exist 4693 // create a new contact 4694 var dataCreateContact = `{ 4695 "email": "${data["email"]}", 4696 "firstname": "${firstname}", 4697 "lastname": "${lastname}", 4698 "properties": { 4699 ${receiveNews ? `"i_agree_to_receive_news___marketing_updates_": "${receiveNews}",` : ""} 4700 "non_signup_actions": "${data['website_action']}", 4701 "pricing_checkout_url": "${pricingCheckoutUrl}", 4702 "simple_product_listing_checkout_timestamp": "${timeSubmit}", 4703 "registration_status": "Non-register", 4704 "form_source": "Website" 4705 } 4706 }`; 4707 4708 jQuery.ajax({ 4709 url: katObject.webAPI + '/wp-json/restful_api/v1/hubspot/create-contact', 4710 type: 'POST', 4711 contentType: 'application/json', 4712 data: dataCreateContact, 4713 success: function(resp) { 4714 if (callback && typeof(callback) == "function") { 4715 callback(); 4716 } 4717 } 4718 }); 4719 } 4720 4721 } 4722 }); 4723 } 4724 } 4725
4726 var katalonHubspot = window.katalonHubspot = new KatalonHubspot(); 4727})();
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.