Connect a form to the Pixel
Call trackLead from your website code with the right form, question and answer identifiers.
This guide is for people integrating the form directly in the website code, for example because the form validates with JavaScript or submits in the background. If you use Forminator, Contact Form 7, Elementor or a plain HTML form, the ready-made script is faster: see Connect your website forms.
Get the example code
- Install the Pixel and verify that it's active on your website.
- Create and publish the form in Setup → Lead forms.
- Open the Connection tab and select Other website.
- Select Prefer to call trackLead from your own code?: an example appears with the form identifier, the question identifiers and, next to each answer, the accepted values.
For the “Demo request” form, the example is:
// Run this when the visitor submits your form
window.CJMPixel.trackLead({
contact: {
firstName: 'Mario', // required
lastName: 'Rossi',
email: 'mario@example.com', // required
phone: '+393331234567',
},
form_responses: [
{
questionId: 'how_many_employees',
questionText: 'How many employees?',
answer: 'VALUE_FROM_YOUR_FORM', // one of: 1-10 | 11-50 | More than 50
},
{
questionId: 'when_do_you_want_to_start',
questionText: 'When do you want to start?',
answer: 'VALUE_FROM_YOUR_FORM', // one of: Right away | Within 3 months | Just exploring
},
],
source_metadata: {
formId: 'demo-request', // must match this form exactly
form_name: 'Demo request',
},
});Replace the example values with what the visitor entered and call trackLead once, when the form was saved successfully.
Check the mapping
| In CJM | In the Pixel |
|---|---|
| Form | source_metadata.formId |
| Question | form_responses[].questionId |
| Answer (the Sent as value, if shown) | form_responses[].answer |
Send the answer value, not a different text shown to the visitor. Identifiers stay the same even if you later change a question's text.
Avoid incomplete or duplicate sends
- Call the Pixel after validation and successful saving, not on a simple Submit click.
- Put name, email and phone in
contact, not in the answers. - Don't call the Pixel twice for the same submission, for example both on click and on confirmation.
- An unrecognized form or question doesn't block the lead, but the answers don't count toward the score.
The Pixel doesn't save the form on your website or confirm delivery: keep your normal form confirmation message. In the Connection tab, the status changes from Waiting for the first lead… to Lead received when the first lead arrives.
For the full list of trackLead fields, see Capture a lead.