Sub topic 11
Capturing leads and passing them to a CRM
This chapter covers what happens after a visitor decides to hand over contact details. You should already know the hub-and-spoke model, how pages are designed to convert, and what UTM parameters are. We assume no programming experience. The short code examples are explained as they appear.
What a lead is and why the handoff matters
A lead is a person who has shared contact details and shown some interest in what you offer. A CRM (customer relationship management system) is the database where a sales or marketing team stores those people, tracks every interaction, and decides who to contact next.
The website is the hub, so most leads are born there. A form submission is only useful if the data reaches the CRM quickly, intact, and with enough context for someone to act on it. Many lead programs fail at this step rather than at the form itself. The form works, but the data is lost, duplicated, mislabeled, or sits unread for days.
Think of the process as a chain with four links:
- The visitor sees an offer and a form.
- The form collects a small amount of data and sends it to your systems.
- The system checks, cleans, and enriches the record.
- The CRM stores it, assigns an owner, and triggers a follow-up.
Designing the form
A form is a trade between how much you learn and how many people finish it. Every extra field lowers the completion rate, so ask only for what you need to take the next step. If you only need to send a guide by email, ask for an email address and nothing else.
Here is the minimal form from the topic plan:
<form action="/subscribe" method="post">
<label for="email">Email address</label>
<input id="email" name="email" type="email" required>
<button type="submit">Get the free guide</button>
</form>Some details in this short example matter:
action="/subscribe"is the address on your server that receives the data, andmethod="post"sends it in the request body rather than in the URL. This keeps email addresses out of browser history and server logs of visited URLs.label for="email"ties the text to the field. Screen readers announce it, and clicking the text focuses the field. A placeholder alone is not a substitute.type="email"makes the browser check the basic format and show the right keyboard on phones.requiredstops an empty submission, but only in the browser.- The button text names the benefit ("Get the free guide") instead of a generic "Submit".
Progressive profiling
You will often want more than an email address, such as company size or role. Asking for everything at once hurts conversion. Progressive profiling spreads the questions over several interactions. The first form asks for an email. A later download asks for a name, and a third asks for company. The CRM keeps what it already knows, and the form shows only fields that are still empty. This needs a tool that recognizes returning visitors, which most marketing automation platforms provide.
Field choices that cause trouble later
- Free-text fields where you need categories. If "Country" is typed freely, you will get "UK", "U.K." and "United Kingdom". Use a dropdown for values you will filter on.
- A single "Name" field. If you want to greet people by first name, collect first and last name separately, or plan to split them.
- Phone numbers with strict formats. Visitors write numbers in many ways. Accept variations and normalize them on the server.
Validation: browser and server
Browser checks such as required and type="email" are for convenience. Anyone can bypass them, and bots send data directly to your action address without loading the page. The server must therefore validate again. It should check that required fields exist, that the email has a plausible format, that lengths are reasonable, and that the content is safe to store.
The following Python example shows the idea using only the standard library. It is a simplified handler, not a full web application:
import re
EMAIL_PATTERN = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
def clean_lead(form: dict) -> dict:
"""Validate a submitted form and return a cleaned record.
Raises ValueError if the data cannot be accepted.
"""
email = form.get("email", "").strip().lower()
if len(email) > 254 or not EMAIL_PATTERN.match(email):
raise ValueError("A valid email address is required")
# Honeypot: a hidden field that humans leave empty and bots fill in.
if form.get("website", ""):
raise ValueError("Rejected as likely spam")
return {
"email": email,
"first_name": form.get("first_name", "").strip()[:100],
"source": form.get("source", "unknown"),
}
if __name__ == "__main__":
submitted = {"email": " [email protected] ", "first_name": "Ada", "source": "spring_sale"}
print(clean_lead(submitted))Running this prints {'email': '[email protected]', 'first_name': 'Ada', 'source': 'spring_sale'}. The email is trimmed and lowercased, which helps later when the CRM checks for duplicates.
The honeypot is a hidden form field that real visitors never see, so they leave it empty. Many simple bots fill every field, which exposes them. For stronger protection, add rate limiting or a CAPTCHA, but weigh the cost: CAPTCHAs add friction and can hurt accessibility.
A format check cannot prove that an address exists or belongs to the person who typed it. If that matters, use double opt-in. The system sends a confirmation email and activates the contact only after the person clicks the link. Double opt-in lowers list size but raises quality, and it provides proof of consent, which the next chapter covers.
Carrying marketing context into the lead record
A name and email tell sales who the person is. They do not tell sales how the person arrived. Capturing the source turns a contact list into data you can use to judge channels.
The UTM parameters you learned about earlier arrive in the page address. For example:
https://www.example.com/spring-sale?utm_source=newsletter&utm_medium=email&utm_campaign=spring_saleThe page can copy those values into hidden form fields, so they travel with the submission. A short script does this:
<form action="/subscribe" method="post">
<input type="hidden" name="utm_source" id="utm_source">
<input type="hidden" name="utm_medium" id="utm_medium">
<input type="hidden" name="utm_campaign" id="utm_campaign">
<label for="email">Email address</label>
<input id="email" name="email" type="email" required>
<button type="submit">Get the free guide</button>
</form>
<script>
const params = new URLSearchParams(window.location.search);
["utm_source", "utm_medium", "utm_campaign"].forEach(function (name) {
const field = document.getElementById(name);
if (field && params.has(name)) {
field.value = params.get(name);
}
});
</script>URLSearchParams reads the query string, which is everything after the ?. The script then fills each hidden field if the matching parameter is present.
This has a limitation. The values exist only on the first landing page. If the visitor clicks to a second page before filling the form, the parameters are gone. Common fixes are to store them in a first-party cookie or in sessionStorage when the visitor first arrives, and to read them back when the form loads. Keep any storage consistent with your consent rules.
Useful fields to store with each lead include:
| Field | Example | Why it helps |
|---|---|---|
| Source, medium, campaign | newsletter / email / spring_sale | Compare channels by lead quality |
| Landing page | /spring-sale | See which pages generate leads |
| Form or offer name | free_guide | Know what the person asked for |
| Timestamp | 2026-11-26T13:11:00Z | Measure response time |
| Consent record | Checkbox text, date, version | Prove permission |
Sending the data to the CRM
There are three common ways to connect a form to a CRM.
- Native integration. Many form builders and website platforms have a built-in connector to popular CRMs. This is the fastest to set up and works for simple cases.
- Automation or middleware tool. A service sits between the form and the CRM and maps fields. It handles moderate complexity, such as routing by country.
- Direct API call. Your server sends the data to the CRM's API (application programming interface, a defined way for software to talk to other software). This gives the most control and requires development work.
| Approach | Setup effort | Control | Typical failure |
|---|---|---|---|
| Native integration | Low | Low | Field mapping limits |
| Middleware tool | Medium | Medium | Task limits, silent errors |
| Direct API | High | High | Code bugs, expired credentials |
A direct API call looks like this in outline. The address and token are placeholders, because every CRM defines its own endpoint and fields:
import json
import os
import urllib.request
def send_to_crm(record: dict) -> int:
"""POST a cleaned lead to a CRM endpoint and return the HTTP status."""
url = os.environ["CRM_CONTACTS_URL"]
token = os.environ["CRM_API_TOKEN"]
request = urllib.request.Request(
url,
data=json.dumps(record).encode("utf-8"),
headers={
"Content-Type": "application/json",
"Authorization": "Bearer " + token,
},
method="POST",
)
with urllib.request.urlopen(request, timeout=10) as response:
return response.statusNotice that the token is read from an environment variable instead of being written in the code. Credentials in source code end up in version control and in front-end bundles where anyone can read them. Never call a CRM API directly from browser JavaScript with a secret key.
Mapping fields and avoiding duplicates
Each CRM has its own fields, with its own names and types. Your form's first_name might need to land in a CRM field called FirstName. A mapping is the list of which form field feeds which CRM field. Check three things:
- Type matches. Sending text to a date field fails or is dropped.
- Allowed values match. If the CRM's "Lead source" list contains "Email" and your form sends "newsletter", the record may be rejected or the value ignored. Agree on a controlled list.
- Required CRM fields are covered. Some CRMs reject a contact without a last name. Decide on a rule, such as storing a placeholder, rather than losing leads.
Duplicates are the most common data quality issue. Someone fills in two forms, so your CRM gets two records. The usual identifier for matching is the email address, which is why the earlier code lowercases it. Prefer an "upsert" operation if the CRM offers one: it updates the record when it exists and creates one otherwise. Decide in advance which value wins when the two records disagree. A common rule is that newer data overwrites older data, except for the original source, which stays fixed so the first-touch attribution is not lost.
Routing, scoring and speed
Once a lead is in the CRM, rules decide what happens next.
- Routing assigns the lead to a person or team, for example by region, product, or company size.
- Lead scoring gives points for fit (job title, company size) and for behavior (pricing page visits, repeat downloads). A threshold defines a marketing qualified lead, which means one that marketing believes is ready to pass to sales.
- Response time matters. Interested visitors often move on within hours, so contacting a high-intent lead quickly generally gives better results than contacting them days later. Set an alert or task so no lead depends on someone remembering to check a list.
Not every lead deserves a salesperson. A person who downloaded a guide may need a few helpful emails first. Define stages that both marketing and sales agree on, and write down what moves a contact from one to the next.
Testing and monitoring the pipeline
Integrations break quietly. A renamed CRM field, an expired token, or a changed form can stop data flowing, and nobody notices until someone asks why leads dropped. Build checks in:
- Submit a test lead after every change to the form, the CRM fields, or the integration. Confirm that it appears with the right values, including source fields.
- Compare counts. The number of form submissions in your analytics goal should be close to the number of new CRM contacts for the same period. A growing gap signals a problem.
- Send failures somewhere visible. Log errors, retry temporary failures, and alert someone on repeated failure. Do not silently discard a lead because the CRM was unavailable.
- Review a sample of records each month for empty fields, odd values, and duplicates.
Common mistakes
- Asking for too many fields on the first form.
- Trusting browser validation and skipping server validation.
- Losing UTM data because it was only captured on the first page.
- Putting secret keys in client-side code.
- Letting free-text fields feed lists that need fixed values.
- Never checking whether submissions arrive in the CRM.
- Collecting data without recording consent.
Exercise
A visitor arrives from an email link with utmcampaign=springsale, browses two other pages, then fills in your newsletter form. In the CRM, the campaign field is empty. What most likely happened, and how would you fix it?
Show answer
The UTM parameters were present only in the URL of the first landing page. By the time the visitor reached the form page, the query string no longer contained them, so the hidden fields stayed empty. Fix it by saving the UTM values in a first-party cookie or sessionStorage when the visitor first lands, then reading them into the hidden fields when the form loads (and only doing so in line with the visitor's consent choices).
Exercise
Your form has required and type="email" on the email field. Why must the server still validate the email, and name two checks it should perform?
Show answer
Browser checks can be bypassed, and bots can post directly to the form's action address without using the page. The server should confirm the email field is present and matches a plausible format, and check that lengths are reasonable. It can also reject honeypot submissions or apply rate limits.
Exercise
A person submits two different forms using "[email protected]" once and "[email protected]" another time, and the CRM shows two contacts. Name one change in the pipeline that prevents this and one rule you should define for conflicting data.
Show answer
Normalize the email address (trim whitespace and lowercase it) before sending, and use an upsert operation that matches on email so the existing record is updated instead of a new one created. For conflicts, define which value wins, for example newer data overwrites older data except for the original source, which is kept as the first-touch value.