Skip to content

Lead Capture API

Endpoint

MethodPathDescription
POST/lead.capturePrimary — accepts lead form submissions
POST/leadDeprecated — backward compatible, emits X-Deprecated + Sunset headers
POST/Deprecated — backward compatible, emits X-Deprecated + Sunset headers

Migration notice: The catch-all lead handler has been replaced by the explicit /lead.capture route. The legacy /lead and / paths remain functional but will be removed after 2026-06-01. Update your integrations to use POST /lead.capture.

How It Works

  1. Accepts POST requests with form data (JSON, application/x-www-form-urlencoded, multipart/form-data, or text/plain)
  2. Extracts lead fields: name, email, phone, project, location, team
  3. Enriches with geolocation data from Cloudflare headers
  4. Looks up visitor's engagement score from tracking sessions
  5. Calculates suspicion score (honeypot, time-to-submit, form velocity)
  6. Finds related projects the visitor previously inquired about
  7. Checks for bot leads (when BOT_LEAD_DETECTION is enabled)
  8. Resolves canonical lead by identity + project (visitor_id > email > phone > IP)
  9. Writes every submit into LeadSubmissions history table
  10. Forwards the enriched payload to a Make.com webhook for new primary leads
  11. Stores canonical lead in D1 Leads table
  12. Returns a 301 redirect to a thank-you page

Expected Fields

FieldDescription
FIRSTNAMELead's first name
EMAILLead's email address
PHONELead's phone number
PROJECTReal estate project name
LOCATIONCity/location
TEAMSource team identifier
DOMAINSource website domain
SOURCELead source (WebSite, FB, 99)
COUNTRYCODECountry dial code (preferred canonical key, e.g. +91)
KEYWORDMarketing keyword
USER_MESSAGEOptional message

Auto-injected by form.js

These fields are added automatically when using the dynamic form builder:

FieldDescription
__visitor_idVisitor ID from tracker.js (localStorage _pg_vid)
__pg_hpHoneypot field value (should be empty for real users)
__pg_ttsTime-to-submit in seconds

Campaign parameters are also auto-injected as __gclid, __utm_source, __utm_medium, __utm_campaign, __utm_term, __utm_content, __fbclid, __msclkid.

Country Code Input Compatibility

Backend normalizes country code keys and always treats them as COUNTRYCODE.

  • Preferred key: COUNTRYCODE
  • Also accepted: countryCode, country_code

Response

On success, the handler returns a 301 redirect to {DOMAIN}/thank-you-{slug} (where {slug} is derived from the referring page path). For AJAX submissions, a JSON response with the redirect URL is returned.

Environment Variables

VariableDescription
ENVIRONMENTdevelopment or production
BOT_LEAD_DETECTIONEnable/disable bot detection

When bot detection is enabled, bot-classified submissions are still stored in D1 for history and investigation; only CRM forwarding is suppressed.