# JavaScript API

> The three calls and two attributes you can use on your pages.

The tag defines one global function, `numbat`, with three commands. Calls
made before the script loads are queued and run once it does. Two
attributes on your own markup name or exclude elements.

## `numbat("track", name)`

Records a custom event for the current page view. To make it a goal, use
the rule type **Custom event** in **Property > Conversions**.

```js
numbat("track", "pricing_calculator_used");
```

| Parameter | Type | Required | Notes |
|---|---|---|---|
| `name` | string | yes | Trimmed. Must be 1 to 120 characters. Longer names are dropped. |

## `numbat("identify", fields)`

Attaches an email address or phone number, and optionally a name, to the
current visitor. The call does nothing when `identity` consent is denied.
See [Consent](/docs/tracking/consent).

```js
numbat("identify", { email: "paul@example.com", name: "Paul Kessler" });
```

| Parameter | Type | Required | Notes |
|---|---|---|---|
| `fields.email` | string | one of email or phone | A name alone is not an identity, and a body with neither is dropped. |
| `fields.phone` | string | one of email or phone | |
| `fields.name` | string | no | |

The object may hold only these three keys. A call with any other key is
ignored.

## `numbat("consent", value)`

Sets consent for one or more axes. See [Consent](/docs/tracking/consent).

```js
numbat("consent", "granted");
numbat("consent", "denied");
numbat("consent", { analytics: true, ad_user_data: false });
```

| Parameter | Type | Required | Notes |
|---|---|---|---|
| `value` | `"granted"`, `"denied"` or object | yes | An object changes only the axes it names with `true` or `false`. |

## Page attributes

### `data-numbat-ignore`

Put it on a form, a field, or an element around them. The script
captures no identity from fields inside it and records no click detail
for it. Password and card-like fields are always excluded.

```html
<form data-numbat-ignore>
  ...
</form>
```

### `data-numbat-name`

Gives a click a readable name. The script records up to 30 clicks per
page view, each with the element's tag. Clicks on an element with this
attribute, or inside one, also record the name.

```html
<button data-numbat-name="Book a demo">Book a demo</button>
```

## Related

- [Consent](/docs/tracking/consent)
