Skip to main content

Making calls from the Web Forms

Use the generic integration snippet below to trigger a Brightcall Speed To Lead call when a visitor submits your website form.

The snippet captures the lead's phone number, name, and email from your form and passes them to Brightcall as custom parameters before initiating the call.

Integration Snippet

/*
* Brightcall Speed To Lead integration snippet
*
* Before using this snippet, replace the placeholder selectors below with
* selectors from your own form:
*
* - #YOUR_FORM_SELECTOR
* - #YOUR_SUBMIT_BUTTON_SELECTOR
* - #YOUR_PHONE_FIELD_SELECTOR
* - #YOUR_NAME_FIELD_SELECTOR
* - #YOUR_EMAIL_FIELD_SELECTOR
*
* The snippet will:
* - capture the phone number, name, and email from your form;
* - pass them to Brightcall as custom parameters;
* - initiate a Speed To Lead call when the form's submit button is clicked.
*/

var callInit = false;

// TODO: Replace with your form selector
var form = document.querySelector('#YOUR_FORM_SELECTOR');

if (form) {

// TODO: Replace with your submit button selector
var formButton = form.querySelector('#YOUR_SUBMIT_BUTTON_SELECTOR');
}

if (form && formButton) {

window.leadCM.formTelInputSelector = function(form) {

// TODO: Replace with your phone field selector
var phone = form.querySelector('#YOUR_PHONE_FIELD_SELECTOR').value;

phone = phone.replace(/[^+\d]/g, '');

return phone;
};

formButton.addEventListener('click', function () {

var phoneNumber = window.leadCM.formTelInputSelector(form);

if (phoneNumber && window.leadCM && window.leadCM.call && !callInit) {

callInit = true;

if (window.leadCM.formBeforeCall) {
window.leadCM.formBeforeCall(
phoneNumber,
form,
function () {
window.leadCM.call(phoneNumber, 'universal_form');
}
);
} else {
window.leadCM.call(phoneNumber, 'universal_form');
}
}
});

window.leadCM.formBeforeCall = function (phoneNumber, form, call) {

// TODO: Replace with your field selectors
var nameInput = form.querySelector('#YOUR_NAME_FIELD_SELECTOR');
var emailInput = form.querySelector('#YOUR_EMAIL_FIELD_SELECTOR');

var userName = nameInput ? nameInput.value : null;
var userEmail = emailInput ? emailInput.value : null;

var custom_params = {
lc_param_phone: phoneNumber
};

if (userName) {
custom_params.lc_param_name = userName;
}

if (userEmail) {
custom_params.lc_param_email = userEmail;
}

leadCM.dispatchCustomEvent(
"CUSTOM_PARAMS",
custom_params,
call
);
};
}

Need help? Contact us at [email protected]

Did this answer your question?