Capture a lead
Every trackLead field, complete examples, and form matching.
Use trackLead to send information a person entered into your form to CJM. A form_submit event or track('lead_submit') call does not replace lead capture.
If you also need to configure form questions and scoring, start with Lead Forms. This guide remains the complete reference for fields sent by the Pixel.
Connect your form
- Install the Pixel and make sure
window.CJMPixelis available. - Choose a stable form identifier. If the form is configured in CJM, use its formId, not the Pixel ID.
- Map contact fields to
contactand answers toform_responses. - Call
trackLeadonce from the successful submission handler, after validation. A click on “Submit” alone does not confirm success. - Submit a test and check the contact and, if answers were supplied, the form submission in CJM.
Signature and fields
window.CJMPixel.trackLead(data, eventName?)
| Field | Type | Required | What to provide |
|---|---|---|---|
data | object | Yes | The three groups below. |
contact | object | Yes | Contact details. |
contact.firstName | string | Yes | First name. |
contact.email | string | Yes | Email address; validate it in your form. |
contact.lastName | string | No | Last name. |
contact.phone | string | No | Phone number, preferably with country code. |
contact.<other field> | JSON-serializable value | No | Extra details such as company; these do not imply automatic CRM field mapping. |
form_responses | array | Yes | One entry per answer, or []. |
form_responses[].questionId | string | Yes, per entry | Stable question identifier. |
form_responses[].questionText | string | Yes, per entry | Question text required by the Pixel's public contract. |
form_responses[].answer | string | Yes, per entry | Answer; convert numbers and multiple selections to strings. |
source_metadata | object | Yes | Originating form. |
source_metadata.formId | string | Yes | Form identifier, matching the configuration in CJM when one exists. |
source_metadata.form_name | string | No | Readable form name. |
eventName | string | No | Second argument, defaults to lead_submit. |
Do not supply cid, sid, timestamps, or consent yourself: the Pixel adds them as permitted. trackLead does not accept options, tags, or destinations.
Complete example
Replace this sample data with actual submitted values.
window.CJMPixel.trackLead({
contact: {
firstName: 'Giulia',
lastName: 'Rossi',
email: 'giulia@example.com',
phone: '+390212345678',
company: 'Example Srl'
},
form_responses: [
{ questionId: 'service', questionText: 'Servizio richiesto', answer: 'Demo CJM' },
{ questionId: 'team_size', questionText: 'Dimensione del team', answer: '12' }
],
source_metadata: {
formId: 'richiesta-demo',
form_name: 'Richiesta demo'
}
}, 'demo_request');Minimal example
window.CJMPixel.trackLead({
contact: { firstName: 'Giulia', email: 'giulia@example.com' },
form_responses: [],
source_metadata: { formId: 'richiesta-demo' }
});form_responses: [] is valid. CJM receives the lead, but only creates an answers record when the array contains at least one answer. An unknown formId does not prevent sending; the submission will not be linked to a matching form configuration.
Connect successful form submission
This defines a handler to call from your form’s success callback, passing its <form> element. Fields must be named firstName, email, and service. This callback name is not an automatic CJM event: connect it to the system that actually saves your form.
function onContactFormSaved(form) {
const fields = new FormData(form);
window.CJMPixel.trackLead({
contact: {
firstName: String(fields.get('firstName') ?? ''),
email: String(fields.get('email') ?? '')
},
form_responses: [{
questionId: 'service',
questionText: 'Servizio richiesto',
answer: String(fields.get('service') ?? '')
}],
source_metadata: { formId: 'richiesta-demo', form_name: 'Richiesta demo' }
});
}Consent and result
Refusing cookies does not block explicitly submitted form data. Visitor and session identifiers still depend on their respective consent signals. This technical behavior does not replace your form's privacy notice.
The function does not return delivery confirmation or replace your website's form storage. Do not display “Request sent” solely because trackLead ran.
Troubleshooting
- No lead: check
contact,form_responses, andsource_metadata. PutfirstNameandemailinsidecontact. - Missing answers: check that the array is nonempty and
questionIdvalues match the expected questions. - Duplicate requests: avoid calling from both the click handler and submission success handler.
- Missing earlier journey: check consent and identity matching. A lead sent without identifiers might not link to earlier visits.