function runWithJQuery(jQueryCode) { if(window.jQuery) { jQueryCode(); } else { var script = document.createElement('script'); document.head.appendChild(script); script.type = 'text/javascript'; script.src = "//code.jquery.com/jquery-3.5.1.js"; script.onload = jQueryCode; } } runWithJQuery(function jQueryCode() { jQuery(document).ready(function($){ (async() => { //console.log("waiting for leadboxer and active demand object to defined"); while(!window.AD || !window.ot_uid ) await new Promise(resolve => setTimeout(resolve, 500)); let i = 0; // wait while(!window.AD || !window.AD.hasOwnProperty('contact_id') || window.AD.contact_id === "" || window.AD.contact_id === "undefined") { //console.log("waiting every 1s"); i+=1; if (i==5) { /* console.log("still fail, sending debugging info"); var map = new OTMap(); map.put("active_demand_troubleshooting_uid", ot_uid()); map.put("active_demand_troubleshooting_sid", ot_sid()); OTLogService.sendEvent("active_demand_troubleshooting", map); */ console.log("waited 5seconds, stop waiting, ad contact_id still empty " + window.AD.contact_id); break; } await new Promise(resolve => setTimeout(resolve, 1000)); } // console.log("window.AD.contact_id is defined => '" + window.AD.contact_id + "'"); // wait while(!window.AD || !window.AD.hasOwnProperty('contact_id') || window.AD.contact_id === "" || window.AD.contact_id === "undefined") await new Promise(resolve => setTimeout(resolve, 500)); // console.log("window.AD.contact_id is defined => '" + window.AD.contact_id + "'"); // let email = window.AD.contact_email; let dataset = 'edc367020dd345d9aee99a90894ab750'; let uid = ot_uid(); // let companyName = ot_gp('companyName'); /* if (!email) { console.log('email is not defined in parameter, aborting...'); return; } */ let active_url = 'https://active.leadboxer.com/api/active/active-demand.jsp?' + 'contactId=' + encodeURIComponent(window.AD.contact_id) + '&dataset=' + encodeURIComponent(dataset) + '&userId=' + encodeURIComponent(uid); //if (companyName) { // active_url += "&companyName=" + encodeURIComponent(companyName); //} /* $.get(active_url, function( data ) { console.log('done ' + data); }); */ $.ajax({ url: active_url, dataType: "jsonp", success: function( response ) { console.log( response ); } }); if (window.AD.contact_email) { active_url = 'https://active.leadboxer.com/api/active/active-demand.jsp?' + 'contactId=' + encodeURIComponent(window.AD.contact_id) + '&dataset=' + encodeURIComponent(dataset) + '&userId=' + encodeURIComponent(uid) + '&title=' + encodeURIComponent('this is a web event') + '&email=' + encodeURIComponent(window.AD.contact_email); $.ajax({ url: active_url, dataType: "jsonp", success: function( response ) { console.log( response ); } }); var map = new OTMap(); map.put("email", window.AD.contact_email); OTLogService.sendEvent("email captured", map, false); } if (ot_gp('ADcontactId')) { let email = ''; if (ot_gp('email')) email = ot_gp('email'); let email_id = ''; if (ot_gp('emailId')) email_id = ot_gp('emailId'); let utm_medium = ''; if (ot_gp('utm_medium')) utm_medium = ot_gp('utm_medium'); let utm_source = ''; if (ot_gp('utm_source')) utm_source = ot_gp('utm_source'); let url_internal_email_link = 'https://active.leadboxer.com/api/active/active-demand-internal-email-link.jsp?' + 'contactId=' + encodeURIComponent(ot_gp('ADcontactId')) + '&dataset=' + encodeURIComponent(dataset) + '&emailId=' + encodeURIComponent(email_id) + '&email=' + encodeURIComponent(email) + '&utmMedium='+ encodeURIComponent(utm_medium) + '&utmSource='+ encodeURIComponent(utm_source); $.ajax({ url: url_internal_email_link, dataType: "jsonp", success: function( response ) { console.log( response ); } }); } })(); // console.log("above code doesn't block main function stack"); }); })