Developer pages

Overview

What humanbehavior-js does in the browser, lifecycle, packages, and the map of every SDK subpage.

Packages

Package / importRole
humanbehavior-jsMain browser package — re-exports core; UMD build available
humanbehavior-js/coreHumanBehaviorTracker, redaction, API client, error capture, tracing
humanbehavior-js/reactHumanBehaviorProvider, hooks, HumanBehaviorErrorBoundary, captureNextError
@humanbehavior/wizardInstall wizard + upload-sourcemaps CLI

Install (typical):

pnpm add humanbehavior-js
# or: npm install humanbehavior-js

What the SDK does in the browser

On HumanBehaviorTracker.init(apiKey, options?) the tracker:

  1. Creates a singleton (window.__humanBehaviorGlobalTracker) and starts immediately (start() is called from init)
  2. Generates sessionId + anonymous endUserId locally (cookie / localStorage) — no bootstrap HTTP call is required
  3. Records replay chunks with rrweb → POST /api/ingestion/events (batched; idle flush ~3s). Users are created on first event
  4. Sends heartbeats (~30s) so idle tabs stay in the dashboard live set → POST /api/ingestion/heartbeat
  5. Ends presence on unload → POST /api/ingestion/session-end
  6. Autocaptures UX signals ($pageview, $click, $form_submitted, $rageclick, $deadclick, …) when automatic tracking is on
  7. Optionally captures console warn/error, network failures, crashes, Core Web Vitals, and performance spans

Default ingestion host when ingestionUrl is omitted: https://ingest.humanbehavior.co.

Minimal install

import { HumanBehaviorTracker } from "humanbehavior-js";

const tracker = HumanBehaviorTracker.init(
  process.env.NEXT_PUBLIC_HUMANBEHAVIOR_API_KEY!,
  {
    ingestionUrl: process.env.NEXT_PUBLIC_HUMANBEHAVIOR_INGESTION_URL,
    redactionStrategy: { mode: "visibility-first" },
    release: process.env.NEXT_PUBLIC_APP_VERSION,
    environment: "production",
  },
);

init returns the tracker instance. Calling init again in the same page returns the existing singleton.

Session timing (shipped constants)

ConstantValueMeaning
Session idle timeout30 minutesSDK rotates sessionId after inactivity (aligned with ingestion)
Session max length24 hoursHard cap before rotation
Minimum duration gate5 seconds (default)Events held until the session is “real”; set minimumDurationMilliseconds: 0 to send immediately
Idle flush3 secondsNormal replay/event batch cadence
Live flush150 msWhen the server signals an active dashboard live viewer

Subpages

PageTopic
Init referenceFull options table + signature rules
Automatic trackingBuilt-in event names and toggles
Custom eventscustomEvent + batching
IdentifyidentifyUser / logout
Replay privacyRedaction modes
Error monitoringCrashes → Issues
Source mapsupload-sourcemaps
Web vitals & tracing$web_vitals + spans
Console & networkLogs / network errors

Public methods (core)

MethodPurpose
start() / stop()Start/stop recording (start is already called by init)
customEvent(name, props?)Product / analytics events
identifyUser(props | { userProperties })Attach traits; upsert via /user
logout()Clear identity + rotate session
captureException(error, options?)Manual handled error
startSpan / startInactiveSpanCustom performance spans
setUnredactedFields / getUnredactedFieldsRuntime redaction helpers
getSessionId()Current session id
setUserProperty(key, value)Set a single user trait locally
getUserAttributes()Read merged user traits

Verify

Verify data is flowing

Common failures

SymptomLikely cause
No dataInit never ran in the browser / wrong API key / SSR-only
Hydration warningsProvider wrapped the entire App Router tree
Blocked requestsAd blocker — use a reverse proxy
Minified stacksMissing source maps
Short sessions missing eventsDefault 5s minimum duration gate