# Browser sensor

> Install the drop-in script that collects client-side abuse signals.

The sensor is a small, dependency-free script that runs in your end-user's browser.
It collects client-side signals that don't exist server-side — automation tells,
behavioral timing, and device fingerprints — and is the client half of [signal
fusion](https://docs.vectoral.si/guides/signal-fusion.md).

> [!NOTE]
>
> The sensor only **collects** signals; it never makes the bot/human decision. That
> always happens server-side. Never trust a client-side verdict for enforcement.

## Install

Add the script to the `<head>` of the page hosting your AI feature, configured with
your **publishable site key**:

```html theme={null}
<script async src="https://cdn.vectoral.cloud/v1/sensor.js?siteKey=pk_live_xxx&endpoint=https://api.vectoral.cloud/v1/sensor/collect"></script>
```

| Parameter | Required | Description |
| - | - | - |
| `siteKey` | yes | Your `pk_live_` publishable key |
| `endpoint` | yes | The collect endpoint (`/v1/sensor/collect`) |
| `debug` | no | Set to `1` to log signals to the console |

The same settings can be given as `data-site-key`, `data-endpoint`, and
`data-debug="true"` attributes on the script tag. Without an `endpoint`, the sensor
returns a local placeholder token and never contacts Vectoral.

## Collect before the protected action

The sensor only posts its signals when you call `getToken()` — loading the script
alone sends nothing. Call it right before the request that triggers your LLM call:

```js theme={null}
const token = await window.vectoral.getToken({ action: "generate" });
```

Fusion uses the most recent collect for the session within the last **5 minutes**, so a
session that never called `getToken()` has no browser signal to fuse.

## Forward the session id

For fusion to work, your backend score call must use the **same** `session_id` the
sensor generated. The sensor exposes it as `window.vectoral.sessionId`. Forward it on
the request that triggers your LLM call:

```js theme={null}
fetch("/api/generate", {
  method: "POST",
  headers: { "X-Vectoral-Session": window.vectoral.sessionId },
  body: JSON.stringify({ /* ... */ }),
});
```

Your backend reads that header and passes it as `session_id` to
[`/v1/score`](https://docs.vectoral.si/api-reference/score).

> [!TIP]
>
> Better still, forward the token from `getToken()` and pass it as
> `request.sensor_token`. The token is signed and bound to your account, so it can't be
> swapped onto another session the way a bare `session_id` can; when it's present it
> takes precedence over `session_id` for the join, and an invalid or expired token
> skips fusion rather than falling back.

## What it collects

> [accordion] Automation tells
>
> `navigator.webdriver`, ChromeDriver `cdc_` properties, headless quirks,
> missing `window.chrome`, and known automation globals (Playwright, Puppeteer,
> Selenium, PhantomJS).

> [accordion] Behavior
>
> Mouse movement and speed, clicks, keystrokes, scrolls, pointer types, and time
> to first interaction. Scripted sessions produce telltale shapes (no interaction,
> teleporting cursors).

> [accordion] Environment
>
> User agent, languages, platform, hardware concurrency, timezone, canvas hash,
> and WebGL renderer — combined into a stable-ish fingerprint.

## Token flow (optional gating)

`/v1/sensor/collect` returns a **signed token** and a soft `decision`. If you want a
real-time gate independent of `/v1/score`, attach that token to a protected request
and verify it server-side with [`/v1/sensor/verify`](https://docs.vectoral.si/api-reference/sensor-verify).
For most integrations, the [score](https://docs.vectoral.si/api-reference/score.md) path is enough — the browser
signal is fused automatically via `request.sensor_token` or `session_id`.
