For AI agents: the complete documentation index is available at https://docs.clickmax.io/en/llms.txt, the full documentation bundle is available at https://docs.clickmax.io/en/llms-full.txt, and this page is available as Markdown at https://docs.clickmax.io/en/reference/browser-sdk/forms/programmatic.md.
  • English
  • 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.

    Requires the Browser SDK loader on the page

    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

    window.cxs('lead', {
      name: 'João da Silva',
      email: '[email protected]',
      telephone: '11999999999',
    }, (err) => {
      if (err) console.error('Failed to create the lead:', err)
    })

    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. 11999999999 or 5511999999999).
    • 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:

    window.cxs('lead', {
      email: '[email protected]',
      customFields: {
        empresa: 'ACME',          // by internal name / label
        Cidade: 'São Paulo',      // label (case-insensitive)
        faturamento: 50000,       // non-text values are accepted
      },
    })

    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 fieldName and displayName.

    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:

    window.cxs('lead', { email: '[email protected]' }, (err) => {
      if (err) {
        // handle the error (e.g. show the form again)
        return
      }
      // success: the lead was created
    })

    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.