Create a lead via JavaScript
Use this page when the lead submission is handled by your own code — a React/Vue funnel, a multi-step form, or any flow where you are not using the data-cx-* attributes.
cxs('lead', ...) only works if the Browser SDK loader is installed in the page's <head>. That is what defines the global cxs. Without the loader, window.cxs is undefined and the call does nothing. See the Introduction to install the script.
With the loader in place, you call lead creation directly with cxs('lead', ...).
Minimal example
Fields
The data object accepts:
email— the lead's email. Required.name— the lead's name.telephone— the lead's phone number. Send digits only (e.g.11999999999or5511999999999).utmSource,utmMedium,utmCampaign,utmTerm,utmContent— traffic attribution.customFields— an object with values for the lead's custom fields. See below.
UTMs present in the page's URL are included automatically. You only need to pass the utm* fields in the payload if you want to override the values from the URL — the value you pass takes precedence.
Custom fields
Pass a customFields object to fill in the lead's custom fields in the CRM. Each key identifies an existing field — it can be the field's id, its internal name (fieldName) or its label (displayName), resolved in that order:
Rules:
- The custom field has to exist already in the CRM. Keys that do not match a field are silently ignored — this endpoint does not create fields.
- Matching is case-insensitive for
fieldNameanddisplayName.
In ordinary HTML forms, the same thing is done declaratively by marking the input with data-cx-field. See Simple forms → Custom fields.
Callback
The second argument is optional and receives an error when creation fails:
Without a callback the call still works; you just do not get the result.
Automatic tracking
When the lead is created successfully, the SDK fires the contact_captured event automatically. You do not need to fire that event yourself. See Tracking.
When to use it
Use cxs('lead', ...) when:
- the form submission is handled by your own JavaScript
- the page is an application (React, Vue, etc.) with no traditional
<form>to mark up - you collect the data in stages and decide exactly when to create the lead
For ordinary HTML forms, prefer the declarative approach with data-cx-ingest-form.