Skip to content

Quickstart

1. Add the script

Add it to every page where people sign in or work. Set the config object before the script loads.

<script>
  window.BehavLabsConfig = {
    apiKey: "pk_beta_your_key",     // publishable key, safe in the page
    userId: currentUser.id,         // your account ID: the same person on every device
    consent: storedChoice ?? null,  // { training: true, policyVersion } or null
  };
</script>
<script src="https://behavlabs.com/sdk/behavlabs-sdk-2.4.0.js" async></script>

Pass your real account ID

Set userId to your account ID for the signed-in user, the same on every device. Scoring compares each session with that person's earlier sessions, so a missing or per-device ID means every visit starts from an empty history and detection is much weaker.

The page's origin must be on your key's allow-list. Pin the versioned file shown here, or self-host a copy: the SDK only needs to reach the API. /sdk/behavlabs-sdk.js without a version always serves the latest release.

Nothing is captured or sent until consent.training is true.

// After the user accepts your notice:
BehavLabs.setConsent({ training: true, policyVersion: "acme-privacy-2026-11" });

// If they decline or later withdraw:
BehavLabs.setConsent({ training: false });

A starting point for the prompt is in End-user notice.

3. Check it runs

Watch the status events in the console, or try everything live in the SDK playground.

BehavLabs.onStatus((s) => console.log("[behavlabs]", s.type, s));
// expect: started, session, sent, ...  (or blocked / refused: see Status events)

4. Read the risk

From your server, poll a session's risk or receive a webhook when it alarms. The SDK gives you the session id (BehavLabs.getSessionId()); pass it to your backend.

curl "https://api.behavlabs.com/v1/collect/sessions/8649741cdcf3427eba8259d8b63e2bbb/risk" \
  -H "Authorization: Bearer $BEHAVLABS_SECRET_KEY"

5. Wire up erasure

On your server, for withdrawals and deletion requests.

# Server side only: never ship the secret key to a browser.
curl -X DELETE "https://api.behavlabs.com/v1/collect/users/u_8f3a91" \
  -H "Authorization: Bearer $BEHAVLABS_SECRET_KEY"