# Universal Lead Capture Embed Form

_Lead Generation_

A drop-in capture form that any website can render with a one-line script tag. Different from the form builder — this is one universal form per org, designed to be the "I just want to capture leads on my site" zero-config option. Captures UTM params + page URL + referrer automatically, dedupes by email, rate-limited per org, and writes Contact rows with source=embed_form.

## Steps
1. Go to /dashboard/leadgen/visitors > expand the External Forms & API card.
2. Copy the snippet at the top (looks like: <script src="…/embed/lead-capture.js" data-org="…" async></script>).
3. Paste it into your site's HTML where you want the form to render. The script auto-mounts wherever it sits, OR if you put a <div data-crmown-lead-capture></div> elsewhere on the page it mounts there instead.
4. Click "Customize form fields & styling" to tweak the form: toggle Name/Phone/Company, set title + subtitle, button text, theme (light/dark/auto), accent color picker, optional redirect URL after submit, success message text. Save.
5. Submissions land in Contacts with source=embed_form, tagged "website-lead". UTMs from the page query string + pageUrl + referrer are stored in customFields for attribution.

## Tips
- Core feature — no suite required. Works on every plan including Starter.
- Theme=auto follows the visitor's OS dark/light preference via prefers-color-scheme. Set to dark or light explicitly to override.
- Dedup-by-email: a returning submitter does NOT create a duplicate Contact. Instead the existing contact gets phone/company filled if missing, and the new captureMeta (UTMs + pageUrl + referrer from this submission) is merged into customFields.
- No external dependencies — the embed JS is ~5KB of vanilla JS, no React/jQuery. Inline styles scope to the form so host-site CSS doesn't leak in.
- The script auto-detects mount points: if you have <div data-crmown-lead-capture></div> on the page, it renders there. Otherwise it renders inline at the script tag's location.
- CORS: the public submit endpoint serves Access-Control-Allow-Origin: * — works from any domain.

## Example
A solo agent on Starter wants a contact form on their personal real-estate site. They copy the snippet, paste it into the contact page (Squarespace), customize: title "Looking to buy or sell?", show Name + Phone (hide Company), accent color matches their brand, success message redirects to /thanks. Two weeks later: 14 leads in CRMown, all tagged website-lead, source=embed_form. Their listing campaign UTMs flow through to attribution — "google / cpc" submissions get a different follow-up sequence than "instagram / story" ones.

## Troubleshooting
- **Form renders but submissions return 429 Rate limit exceeded** — Hit 100/hour per org. Either real burst traffic or a script in a loop. Bots typically trigger this. Fix: Wait an hour and the bucket resets. If it's a bot, add a CAPTCHA on your site (we don't enforce one — keeping the snippet drop-in zero-config). If it's real traffic, contact support to raise the cap.
- **Submissions create new contacts but customFields are empty** — The submitter landed on the page directly without UTMs or a referrer. Fix: Working as designed — UTMs are best-effort; not all visits have them. Contact still gets source=embed_form for the channel attribution.
- **Form looks broken (unstyled) on my site** — Host CSS is overriding inline styles via more-specific selectors. Fix: Wrap the script tag (or the data-crmown-lead-capture div) inside a container that sets `all: initial; font-family: sans-serif;` to reset host styles. Or move the embed to an iframe (not officially supported but works).
- **data-org missing — script does nothing** — Copied an old version of the snippet without the data-org attribute, OR the data-org value is empty. Fix: Re-copy from /dashboard/leadgen/visitors > External Forms & API. The fresh snippet always has your orgId.

## Plans
Core — no suite required. Works on Starter, Pro, Max.
