var $ = jQuery; $(document).ready(function bpm_init_form() { const url = 'https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8'; const isLeaderEnabled = url.indexOf('leader') > -1; const forms = document.querySelectorAll('form'); for (let form of forms) { form.action = url; if (isLeaderEnabled) { insert_leader_inputs(form); form.onsubmit = (e) => { e.preventDefault(); e.stopPropagation(); fetch(form.action, { method: 'POST', body: new FormData(form) }).then((response) => { if (response.ok) { const retURL = form.querySelector('[name="retURL"]'); if (retURL) { window.location.href = retURL; } else { console.log('WARNING: Missing retURL field in lead gen form!'); window.location.reload(); } } }) }; } } if (isLeaderEnabled) { if (!set_leader_inputs) { throw new Error('Leader integration is expected but it looks like the Leader plugin is not installed on this site!'); } set_leader_inputs(gt_cc_utm_source); } function insert_leader_inputs(form) { const leaderFieldsContainer = document.createElement('div'); leaderFieldsContainer.id = 'hidden-leader-fields'; leaderFieldsContainer.style.display = 'none'; const campaignId = document.createElement('input'); campaignId.type = 'hidden'; campaignId.name = 'campaignid'; campaignId.value = '11162'; leaderFieldsContainer.appendChild(campaignId); const utmSource = document.createElement('input'); utmSource.name = 'utm_source'; utmSource.className = 'utm_class_leader'; leaderFieldsContainer.appendChild(utmSource); const fields = [ 'utm_medium', 'utm_term', 'utm_campaign', 'utm_content', 'content_site', 'gclid', 'fbclid', 'cid', 'AgId', 'AdPos', 'device', 'GeoLoc', 'lp', 'ga4_tid', 'ga4_cid', 'fbq_account', 'fbq_client', 'fbq_time' ]; for (let field of fields) { const fieldInput = document.createElement('input'); fieldInput.type = 'hidden'; fieldInput.name = field; leaderFieldsContainer.appendChild(fieldInput); } form.appendChild(leaderFieldsContainer); } });