Tracking Form Submissions in CustomerLabs
Form submissions are actions that users perform when they fill out and submit a form on your website. Tracking these events is essential for lead generation and understanding user intent.
Form Submission Events
Section titled “Form Submission Events”The following events are commonly used to track form interactions in CustomerLabs:
Form SubmittedLead GeneratedContact Us Form SubmittedNewsletter SubscribedRegistration Completed
Properties Object
Section titled “Properties Object”Common Parameters
Section titled “Common Parameters”The following parameters are recommended (not mandatory) for form submission events. These should be included in the customProperties object.
| Parameter | Type | Description |
|---|---|---|
form_name | string | The name or ID of the form. |
form_id | string | The unique identifier for the form. |
page_url | string | The URL where the form was submitted. |
Either one of these will have to mandatorily be passed on to create a user profile. These should be included in the user_traits and external_ids object.
| Parameter | Type | Description |
|---|---|---|
email | string | The email of the user. |
phone | string | The phone number of the user. |
Standard Form Submission
Section titled “Standard Form Submission”This event is triggered when a user successfully submits a form. It is crucial to capture user details like email or phone to identify the user.
Syntax
Section titled “Syntax”var properties = { "customProperties": { // Event properties // User traits (email, name, etc.) // External IDs // Identity mapping }}_cl.trackClick("Form Submitted", properties)Example - Lead Form Submission
Section titled “Example - Lead Form Submission”In this example, we capture user information and trigger both the trackClick event and the identify call.
var eventName = "Contact Us Form Submitted";
var properties = { "customProperties": { "form_name": { "t": "string", "v": "Contact Sales Form" }, "form_id": { "t": "string", "v": "contact_sales_001" }, "user_traits": { "email": { "t": "string", "v": "john.doe@example.com" }, "first_name": { "t": "string", "v": "John" }, "last_name": { "t": "string", "v": "Doe" }, "phone": { "t": "string", "v": "9876543210" }, "company": { "t": "string", "v": "ABC Corporation" } }, "external_ids": { "identify_by_phone": { "t": "string", "v": "9876543210" } }, "identify_by_email": { "t": "string", "v": "john.doe@example.com", "ib": true } }};
// Trigger the event_cl.trackClick(eventName, properties);
// Identify user if email existsvar email = properties.customProperties.identify_by_email.v;
if (email) { _cl.identify(properties);}Multi-step Form Submission
Section titled “Multi-step Form Submission”Multi-step forms collect user information across several pages or steps. The key to tracking them correctly in CustomerLabs is:
- First step capturing email or phone → Trigger
Create userevent to create the user profile. - Subsequent steps capturing more PII → Trigger
Update userevent to update the existing user profile without creating a duplicate.
Step 1 – Capture Email / Phone (Create User)
Section titled “Step 1 – Capture Email / Phone (Create User)”This is the first step of the form where the user enters their email or phone number. Use Create user here to create the user profile.
// Step 1: User enters their name and emailvar properties = { "customProperties": { "form_name": { "t": "string", "v": "Registration Form - Step 1" }, "form_id": { "t": "string", "v": "registration_form_001" }, "user_traits": { "first_name": { "t": "string", "v": "John" }, "last_name": { "t": "string", "v": "Doe" }, "phone": { "t": "string", "v": "9876543210" } }, "identify_by_phone": { "t": "string", "v": "9876543210", "ib": true } }};
// Trigger the form step event_cl.trackClick("Quiz Started", properties);
var email = properties.customProperties.identify_by_email.v;
// Create the user profileif (email) { _cl.identify(step1Properties); // Creates the user in CustomerLabs}Step 2 – Capture Additional PII (Update User)
Section titled “Step 2 – Capture Additional PII (Update User)”In subsequent steps, the user fills in personal details like address, city, zip, and gender. Use _cl.identify(properties, "Update user") to update the existing profile without creating a new one.
// Step 2: User enters their location and demographicsvar properties = { "customProperties": { "user_traits": { "email": { "t": "string", "v": "john.doe@example.com" }, "dob": { "t": "string", "v": "1990-01-01" }, "gender": { "t": "string", "v": "Male" } }, "external_ids": { "identify_by_email": { "t": "string", "v": "john.doe@example.com" } } }};
// Update the existing user profile — does NOT create a duplicate_cl.identify(properties, "Update user");_cl.trackClick("Quiz Step 2 Completed", properties);Step 3 – Final Submission
Section titled “Step 3 – Final Submission”The final step triggers the actual form submission event, tying all the collected data together.
// Step 3: Final form submissionvar properties = { "customProperties": { "user_traits": { "address1": { "t": "string", "v": "123, Main Street" }, "city": { "t": "string", "v": "Los Angeles" }, "state": { "t": "string", "v": "CA" }, "zip": { "t": "string", "v": "90001" }, "country": { "t": "string", "v": "USA" } } }};
// Trigger the final lead event_cl.trackClick("Quiz Completed", properties);
// Update user with final details_cl.identify(properties, "Update user");Next Steps
Section titled “Next Steps”Now that you’ve set up form tracking, you might want to look at: