Embed script
Works on any site that lets you add HTML: WordPress, Webflow, Framer, Wix custom code or a hand-built page. The script is about 5 KB and has no dependencies.
Install
Add the script once, anywhere on the page, then mark each form you want to capture with data-leadvane-form.
Forms marked data-coweb-form keep working for one more release, including the coweb:success events and the .coweb-success class. Rename them to data-leadvane-form when you next edit the site.
<script src="https://leadvane.cowebofficial.workers.dev/embed.js" data-site-key="pk_your_site_key" defer></script>
<form data-leadvane-form="booking" data-success="Thanks! We'll reply within one working day.">
<input name="name" required>
<input name="email" type="email" required>
<input name="phone" type="tel">
<select name="guests"><option>2</option><option>10+</option></select>
<textarea name="message"></textarea>
<button>Send enquiry</button>
</form>Any field names work. They're stored as-is, and export columns are created from them.
Form attributes
| Attribute | Description |
|---|---|
data-leadvane-form | Required. The form name, e.g. contact. Used for filtering and routing. |
data-success | Replace the form with this message after a successful submit. |
data-success-redirect | Go to this URL after success instead, e.g. /thank-you. |
data-error | Custom error message. Shown in an element with data-leadvane-error if present, otherwise appended to the form. |
Script attributes
| Attribute | Description |
|---|---|
data-site-key | Required. Your website's public key. |
data-endpoint | Optional. Override the API address. Defaults to the address the script was loaded from. |
data-fallback-endpoint | Optional. Comma-separated addresses tried when the main one can't be reached, e.g. your workers.dev address behind a custom domain. |
data-auto-capture="on" | Also capture the site's existing forms that have an email or phone field, with no changes to them. Forms with a password field, search forms and forms marked data-leadvane-ignore are skipped. The form name is its name or id. |
data-lang | Language for built-in messages, e.g. hi. Defaults to the page's <html lang>, then the browser. See Languages. |
data-debug | Logs which forms are captured and checks the key and allowed domains against the server. Remove it once leads arrive. |
Reserved field names
| Field | Purpose |
|---|---|
_consent | Consent checkbox. Recorded with a timestamp. Required when the website has Require consent switched on. |
_hp | Honeypot. Added automatically and hidden; bots that fill it are silently dropped. |
cf-turnstile-response | Cloudflare Turnstile token. Checked when a Turnstile secret is saved for the website. |
Any other field starting with an underscore is ignored.
Styling and events
While a form submits, it gets data-state="submitting", then success or error. Submit buttons are disabled during the request.
form[data-state="submitting"] button { opacity: .6; cursor: progress; }
.leadvane-success { padding: 24px; border-radius: 12px; background: #f2fbd4; }Listen for events to run your own code, for example analytics:
document.addEventListener('leadvane:success', (e) => {
gtag('event', 'generate_lead', { form: e.target.dataset.leadvaneForm });
});
document.addEventListener('leadvane:error', (e) => console.warn(e.detail.error));Submitting from your own JavaScript
The script exposes window.Leadvane with the site key already set:
const result = await window.Leadvane.submitLead({
formName: 'callback',
data: { name: 'Asha', phone: '+91 98765 43210' },
});
// { ok: true, id: 'ld_…' } or { ok: true, queued: true } or { ok: false, error: 'rate_limited' }How a lead always gets through
Each submission carries one ID, and Leadvane ignores repeats of an ID, so none of these steps can create a duplicate:
- Send with an 8-second timeout.
keepalivelets it finish even if the visitor leaves the page. - Retry twice with backoff on network errors, timeouts, 5xx and 429 (respecting
Retry-After). A 4xx, such as a domain that isn't allowed, is not retried. - Fallback endpoints from
data-fallback-endpoint, in order. - Offline queue in the visitor's browser (in memory if storage is blocked), retried on a schedule, when the connection returns, when the tab is shown again and on the next page load, for up to 7 days. The visitor sees the success message, or "we'll send this as soon as you're back" when they are offline.
- sendBeacon when the page closes, for anything still queued.
- Normal form post as a last resort, when scripts can't reach the server and the browser can't store the lead (a strict Content-Security-Policy, an aggressive blocker, storage disabled). The page reloads with
?lead=okand the success message shows. Turn this off per form withdata-native-fallback="off".
The form gets data-state="queued" and fires leadvane:queued when a lead is waiting in the queue. window.Leadvane.pendingLeads() returns how many are waiting and window.Leadvane.flushQueue(true) retries now.
Without JavaScript
A plain HTML form can post directly. After saving, the visitor is redirected back with ?lead=ok added to the URL.
<form action="https://leadvane.cowebofficial.workers.dev/v1/submit/pk_your_site_key" method="POST">
<input type="hidden" name="_form" value="contact">
<input type="hidden" name="_redirect" value="https://yourbusiness.com/thank-you">
<input name="email" type="email" required>
<textarea name="message"></textarea>
<button>Send</button>
</form>Use the script and keep action and method on the form, as in the dashboard snippet: with JavaScript you get retries and the offline queue, without it the form still posts. _redirect must point at one of your allowed domains.
No website at all? Turn on Hosted form for the website and share https://leadvane.cowebofficial.workers.dev/f/pk_…, for example in an Instagram bio or a QR code.
Adding Cloudflare Turnstile
Add the Turnstile widget inside your form and save the Turnstile secret key under Websites → Settings. The token is read from the cf-turnstile-response field automatically.
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<form data-leadvane-form="contact">
…
<div class="cf-turnstile" data-sitekey="your-turnstile-site-key"></div>
<button>Send</button>
</form>