React & Next.js SDK
@leadvane/sdk gives you submitLead() for any JavaScript app and a useLeadForm() hook for React. It includes UTM capture, the offline queue and duplicate protection.
Install
npm install @leadvane/sdkBefore the package is published
Install straight from the repository instead: npm install ../lead-service/packages/sdk, or copy packages/sdk/src into your project.
useLeadForm()
Pass the hook's submit to your form's onSubmit. It reads the fields through FormData, so uncontrolled inputs need no state.
'use client'; // Next.js App Router
import { useLeadForm } from '@leadvane/sdk/react';
export function ContactForm() {
const { submit, isSubmitting, isSuccess, error } = useLeadForm({
siteKey: 'pk_your_site_key',
endpoint: 'https://leadvane.cowebofficial.workers.dev',
formName: 'contact',
});
if (isSuccess) return <p>Thanks! We'll be in touch shortly.</p>;
return (
<form onSubmit={submit}>
<input name="name" required />
<input name="email" type="email" required />
<textarea name="message" />
<input name="_hp" tabIndex={-1} autoComplete="off" hidden />
<button disabled={isSubmitting}>{isSubmitting ? 'Sending…' : 'Send'}</button>
{error && <p role="alert">{error}</p>}
</form>
);
}For controlled forms, call submit({ name, email, message }) with a plain object instead of the event.
Options and return values
| Option | Description |
|---|---|
siteKey | Required. Your website's public key. |
endpoint | Base URL of your Leadvane deployment. |
formName | Form name used for filtering and routing. Defaults to default. |
onSuccess(result) | Called after a successful or queued submission. |
The hook returns submit, status (idle | submitting | success | error), error, result, reset, isSubmitting and isSuccess.
submitLead()
Framework-free; works in Vue, Svelte or plain scripts.
import { submitLead } from '@leadvane/sdk';
const result = await submitLead({
siteKey: 'pk_your_site_key',
endpoint: 'https://leadvane.cowebofficial.workers.dev',
formName: 'quote',
data: { name: 'Karan Shah', email: 'karan@company.in', budget: '₹4L' },
consent: true, // optional, recorded with a timestamp
turnstileToken: token, // optional, when Turnstile is enabled
});
if (result.ok) console.log(result.queued ? 'Saved offline, will resend' : `Saved as ${result.id}`);
else console.error(result.error); // e.g. 'consent_required'What the SDK does for you
- One request per lead. Data is sent as a CORS "simple request", so browsers skip the extra preflight call.
- UTM attribution. UTM tags,
gclidandfbclidfrom the landing page are remembered for 30 days and attached to the lead. - Offline queue. Network errors, 5xx and 429 responses are queued in
localStorageand resent on the next load or when the browser comes back online.flushQueue()triggers it manually. - No duplicates. Every submission carries a unique ID; the server ignores repeats.
Error codes
| error | Cause |
|---|---|
origin_not_allowed | The page's domain isn't in the website's allowed domains. |
unknown_site | Wrong or rotated site key. |
consent_required | The website requires consent and none was given. |
captcha_failed | Turnstile token missing or invalid. |
empty_submission / invalid_body | No usable fields, or the body was not valid JSON or over 32 KB. |