[invisit](https://invisit.dev) · [Docs](https://invisit.dev/docs) · [llms.txt](https://invisit.dev/llms.txt) · [llms-full.txt](https://invisit.dev/llms-full.txt)

# @invisitdev/web reference

> Every function and type in @invisitdev/web, the browser tracker as a typed ES module, with signatures, return values and behavior.

Source: https://invisit.dev/docs/reference/web

```ts title="@invisitdev/web"
import { consent, feedback, flush, identify, init, sendFeedback, track } from '@invisitdev/web'
```

Every function except `init()` forwards to the running tracker. Calls made before `init()` are queued and applied once it starts. On the server every function is a silent no-op.

## init

```ts title="@invisitdev/web"
function init(options: InitOptions): Tracker | undefined
```

Starts the tracker once per page and returns it. Calling it again returns the same tracker, and warns when `debug` is on. The options are listed in [Install with npm](https://invisit.dev/docs/web/installation.md#options).

It returns `undefined`:

- on the server, with no `window` or `document`;
- while a site owner has the heatmap overlay open;
- for a browser that [opted out](https://invisit.dev/docs/guides/privacy.md#your-own-visits) with `#invisit-ignore`;
- in a browser driven by automation, such as Playwright, Puppeteer or Selenium, where `navigator.webdriver` is true, unless `debug` is on;
- without a `site`.

If the script tag already started invisit on the page, `init()` reuses that tracker and ignores its own options.

## track

```ts title="@invisitdev/web"
function track(name: string, properties?: Properties, options?: { actionId?: string }): void
```

Records a custom event. See [Custom events](https://invisit.dev/docs/guides/events.md) for naming rules and limits.

## identify

```ts title="@invisitdev/web"
function identify(externalUserId: string): void
```

Links the visitor to your own user id, up to 128 characters, stored hashed. See [Identifying users](https://invisit.dev/docs/guides/events.md#identify-signed-in-users).

## consent

```ts title="@invisitdev/web"
function consent(state: 'granted' | 'denied' | 'unknown'): void
```

Records the visitor's consent answer. `'denied'` stops all collection; with `requireConsent: true`, nothing is sent until `'granted'`; `'unknown'` forgets the answer. Remembered on the device unless `storage: 'none'`.

## feedback

```ts title="@invisitdev/web"
function feedback(): void
```

Opens the feedback widget, when the site has it enabled in the dashboard.

## sendFeedback

```ts title="@invisitdev/web"
function sendFeedback(input: { message: string; email?: string }): Promise<boolean>
```

Sends one message from your own feedback form. Resolves to `true` once the collector accepted it, and to `false` when there is no running tracker.

## flush

```ts title="@invisitdev/web"
function flush(): void
```

Sends queued events now instead of with the next batch. Useful right before a hard navigation you control.

## Tracker

The object `init()` returns has every function above, plus:

| Member                          | What it does                                                                |
| ------------------------------- | --------------------------------------------------------------------------- |
| `conversion(name, properties?)` | Records a conversion, reported apart from ordinary events.                  |
| `pageview()`                    | Records a page view now. Only needed for navigation the tracker cannot see. |
| `stop()`                        | Stops the tracker and removes its listeners.                                |
| `version`                       | The tracker version.                                                        |

## Types

```ts title="src/analytics.ts"
import type {
  ConsentState,
  FeedbackMessage,
  InitOptions,
  Properties,
  Tracker,
} from '@invisitdev/web'
```

## Source

The package is MIT-licensed and [published in full](https://github.com/berkinory/invisit-sdk), built with signed npm provenance from the commit it names.
