Capture leads

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/sdk
Before 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

OptionDescription
siteKeyRequired. Your website's public key.
endpointBase URL of your Leadvane deployment.
formNameForm 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

Error codes

errorCause
origin_not_allowedThe page's domain isn't in the website's allowed domains.
unknown_siteWrong or rotated site key.
consent_requiredThe website requires consent and none was given.
captcha_failedTurnstile token missing or invalid.
empty_submission / invalid_bodyNo usable fields, or the body was not valid JSON or over 32 KB.