# JavaScript API

> Reference for the venbit() function, which reports leads, custom events, missing pages, form results, sign-ups and purchases from your own code.

Source: https://venbit.com/docs/developer-guide/javascript-api
Part of the Venbit Intelligence docs (Developer Guide). Index of every page: https://venbit.com/docs/llms.txt
Last updated: 2026-11-30

The tracker adds a single global function, `venbit()`. Your own code calls it to report what the tracker can't see by itself, such as a lead, a named event, a missing page, the result of a form, a sign-up or a payment.

```js
venbit('lead');
venbit('404');
venbit('event', 'pricing_viewed', { value: 5 });
venbit('signup', { name: 'Dana Whitfield', email: 'dana@harborroofing.example', plan: 'Free trial' });
venbit('subscribe', { value: 49, currency: 'USD', plan: 'Pro', id: 'sub_1042' });
venbit('purchase', { value: 129.5, currency: 'USD', id: 'order_8841' });
venbit('form_success', 'contact', { form: document.getElementById('contact') });
const url = venbit('link', 'https://app.harborroofing.example/signup');
```

Once the tracker line is on the page, the function exists. You'll find the line, with your site's key in place of `KEY`, in the dashboard under **Settings**, then **Tracking**.

```html
<script defer crossorigin="anonymous" src="https://vnbt.app/m.js?s=KEY" data-site="KEY"></script>
```

`venbit()` never throws. Pass it arguments it doesn't understand and it does nothing.

## Call it before the tracker loads

Because the tracker tag is deferred, an inline script or your app's first render can run ahead of it. Put this stub before your first call. Calls wait in `venbit.q` and get played back in order once the tracker loads.

```html
<script>
  window.venbit = window.venbit || function () { (venbit.q = venbit.q || []).push(arguments); };
</script>
```

**With the stub in place, early calls wait for the tracker**

1. Your code calls venbit() (Before the tracker has loaded)
2. venbit.q (The stub holds the call)
3. Tracker loads (Calls are played back in order)

If the tracker never loads (behind an ad blocker, say), the stub also keeps your code from failing. If you'd rather skip it, guard each call instead:

```js
window.venbit?.('event', 'pricing_viewed');
```

A queued call returns nothing. That only matters for `venbit('link', url)`, covered below.

## venbit('lead')

Marks a lead by hand, for a win that isn't a form, a phone tap or an email click. It's counted as a lead the same way a form send is, with no field values, and goes out at once.

```js
venbit('lead');
venbit('lead', 'callback-requested');
```

| Parameter | Type | Required | Meaning |
| --- | --- | --- | --- |
| label | string | No | A name for this lead. Defaults to `manual`. |

Real forms should go through the form calls below, which keep what the visitor typed and run the normal spam checks. Accounts and payments have `signup`, `subscribe` and `purchase`.

## venbit('404')

Reports the current page as missing.

```js
venbit('404');
```

When your server answers with a 404 or 410 status, the page is reported automatically. You only need this call for a "not found" screen your app draws while the server answers 200. Each path is reported once per page load.

## venbit('event', name, props)

Records a named event on the visit.

```js
venbit('event', 'quote_calculator_used');
venbit('event', 'video_watched', { value: 75 });
```

| Parameter | Type | Required | Meaning |
| --- | --- | --- | --- |
| name | string | Yes | The event's name, up to 80 characters. |
| props.value | number | No | A number to store with the event. Anything that isn't a number is ignored. |

You'll see the event as a step in the visitor's [trail](https://venbit.com/docs/md/user-guide/visitor-trails.md). Set a [goal](https://venbit.com/docs/md/user-guide/goals.md) to match the event's name and it counts as a completion. Matching is on the whole name, ignoring case. Only `value` is kept. Any other key in `props` is dropped.

## venbit('signup' | 'subscribe' | 'purchase', props)

Reports an account, the start of a paid plan, or a one-off payment. These go out at once.

```js
venbit('signup', { name: 'Dana Whitfield', email: 'dana@harborroofing.example', plan: 'Free trial' });
venbit('subscribe', { value: 49, currency: 'USD', plan: 'Pro', email: 'dana@harborroofing.example', id: 'sub_1042' });
venbit('purchase', { value: 129.5, currency: 'USD', email: 'dana@harborroofing.example', id: 'order_8841' });
```

| Property | Type | Meaning |
| --- | --- | --- |
| name | string | Who it was. Up to 80 characters. |
| email | string | Their email. Up to 160 characters. |
| plan | string | The plan's name. Up to 60 characters. |
| value | number | The amount, in the currency given (49 or 49.99). Zero or more, rounded to two decimals. |
| currency | string | A currency code such as `USD`. |
| id | string or number | Your own id for the order or account. Up to 64 characters. The same id is counted once. |

All properties are optional. The calls feed the **Sign-ups**, **Subscriptions** and **Purchases** goals under **Settings**, then **Goals**. Pass a name or email and the Inbox shows who it was. For de-duplication, app mode and a full example, see [Sign-ups and purchases](https://venbit.com/docs/md/developer-guide/sign-ups-and-purchases.md).

## venbit('link', url)

When your code navigates to your other domain (say, from the marketing site to `app.yoursite.com`), this returns the address to send the visitor to. A sign-up over there then gets credited to the ad or page that brought them.

```js
const target = 'https://app.harborroofing.example/signup';
window.location.href = window.venbit('link', target) || target;
```

| Parameter | Type | Required | Meaning |
| --- | --- | --- | --- |
| url | string | Yes | Where you're about to send the visitor. |

If the host is one you listed under **Settings**, then **Goals**, as the place people sign up, you get the same address back with the visit attached. Any other address comes back as `url`, unchanged. Ordinary `<a href>` links to a listed host are handled without this call, so reach for it only in code that navigates by itself. The `|| target` covers a call the stub queued, which returned nothing.

## venbit('form_attempt' | 'form_success' | 'form_failure', formName, props)

Reports what happened to a form your code sends. Most forms are tracked automatically. For custom and JavaScript-drawn forms, these calls make the result exact.

```js
const form = document.getElementById('contact');

venbit('form_success', 'contact', { form, submissionId: 'msg_20931' });
venbit('form_failure', 'contact', { form });
```

| Parameter | Type | Required | Meaning |
| --- | --- | --- | --- |
| type | `'form_attempt'`, `'form_success'` or `'form_failure'` | Yes | A send was started, it was accepted, or it was refused. |
| formName | string | No | Which form: its `data-venbit-form` value, `id` or `name`. Ignored when `props.form` is given. |
| props.form | Element or string | No | The form element (or its container). The most reliable way to say which form. |
| props.values | object | No | Field values as `{ Label: value }`, for a form whose values aren't in the page's inputs. |
| props.submissionId | string | No | Your id for this submission. A result with the same id is counted once per page. |

`form_success` records a sent form. If it's an enquiry form, that's a lead in the [Inbox](https://venbit.com/docs/md/user-guide/inbox.md), carrying the values the tracker read from its fields plus any you pass. `form_failure` records a failed send, which isn't a lead. And `form_attempt` marks a send that has started, for forms with no ordinary submit button or submit event.

Leave out both `formName` and `props.form` and the call applies to the one form on the page with a send in progress. [Form tracking](https://venbit.com/docs/md/developer-guide/form-tracking.md) has the details, including how a form is found by name.

## Other names

Any other first argument gets recorded as a plain click, labelled with the second argument (or the name itself). If you want to build a goal on it, use `venbit('event', name)`.

## Calls you won't find

There's no identify call, so you can't attach your own user id to a visitor. `signup`, `subscribe` and `purchase` can carry a name and email for that one event.

Page views have no call either. They're counted automatically, single-page route changes included (see [Single-page apps](https://venbit.com/docs/md/developer-guide/single-page-apps.md)).

Opting out isn't a JavaScript call. A browser opts out by opening the site with `?vb_optout=1` on the address, and back in with `?vb_optout=0`. See [Privacy controls](https://venbit.com/docs/md/developer-guide/privacy-controls.md).

## TypeScript

Drop this into a `.d.ts` file in your project (`venbit.d.ts`, for example).

A coding agent can also write the file for you. The prompt's version declares `venbit` as a global too, so bare `venbit(...)` calls type-check alongside `window.venbit(...)`.

```prompt
Add TypeScript types for the Venbit tracker's global venbit() function. Create venbit.d.ts with a Venbit interface of call signatures: ('lead', label?), ('404'), ('event', name, { value?: number }), ('signup' | 'subscribe' | 'purchase', { name, email, plan, value, currency, id }), ('link', url) returning string | undefined, and ('form_attempt' | 'form_success' | 'form_failure', formName?, { form, values, submissionId }), plus q?. Inside declare global, declare both interface Window { venbit: Venbit } and var venbit: Venbit. End with export {}.
```

```ts
type VenbitConversion = {
  name?: string;
  email?: string;
  plan?: string;
  value?: number;
  currency?: string;
  id?: string | number;
};

type VenbitFormResult = {
  form?: Element | string;
  values?: Record<string, string | number | boolean | Array<string | number>>;
  submissionId?: string;
};

interface Venbit {
  (type: 'lead', label?: string): void;
  (type: '404'): void;
  (type: 'event', name: string, props?: { value?: number }): void;
  (type: 'signup' | 'subscribe' | 'purchase', props?: VenbitConversion): void;
  (type: 'link', url: string): string | undefined;
  (
    type: 'form_attempt' | 'form_success' | 'form_failure',
    formName?: string,
    props?: VenbitFormResult
  ): void;
  q?: IArguments[];
}

declare global {
  interface Window {
    venbit: Venbit;
  }
}

export {};
```

## Common questions

### What happens if venbit() is called and the tracker is blocked?

When the tracker never loads (an ad blocker is the usual cause), `venbit` doesn't exist and a bare call fails. Add the queue stub before your first call, or guard each call with `window.venbit?.(...)`. With the tracker loaded, `venbit()` never throws.

### What data can I send with a Venbit custom event?

`venbit('event', name, props)` takes a name of up to 80 characters and an optional numeric `props.value`. Other keys in `props` are dropped, and a non-numeric `value` is ignored.

### How do I turn a custom event into a goal in Venbit?

Set a [goal](https://venbit.com/docs/md/user-guide/goals.md) to match the event's name. Matching is on the whole name and ignores case, so `venbit('event', 'quote_calculator_used')` completes a goal named `quote_calculator_used`.

### Why does venbit('link') return nothing?

Calls made before the tracker loads are queued by the stub, and a queued call returns nothing. Write `window.venbit('link', target) || target` so the visitor still lands on the right address.

### Can I opt a visitor out of Venbit from JavaScript?

There's no `venbit()` call for it. A browser opts out by opening the site with `?vb_optout=1`, or your code can set `localStorage.setItem("vb_optout", "1")` as shown in [Privacy controls](https://venbit.com/docs/md/developer-guide/privacy-controls.md).
