Developer pages

HTML / Vanilla JS

Install HumanBehavior in bundled HTML or a static page, including wizard detection, npm entry, and CDN global names.

The HTML guide is for browser pages without a detected JS framework. The wizard path assumes a bundled HTML/JS project; the published SDK also exposes browser bundle metadata for CDN use.

Wizard detection

The wizard's HTML config is the broadest fallback and runs last. It matches when:

SignalDetails
index.htmlRoot HTML file exists
public/index.htmlPublic HTML fallback
src/index.htmlSource HTML fallback
<script in those filesScript-bearing HTML is considered a browser app

This is only reached after Next, Nuxt, Vue, Remix, Svelte, Angular, Astro, Gatsby, and React fail detection.

Supported install shapes

ShapeStatus
Bundled HTML/JS with npm packageShipped wizard reference path
Static HTML using published unpkg/jsdelivr bundlePackage metadata exposes bundle; install manually
Backend-only project with no browser HTMLNot a shipped wizard target
HTML file with no package manager/build and no place to persist env varsWizard support is limited; manual install may be required

Package install for bundled HTML

pnpm add humanbehavior-js

Environment variables for Vite-bundled HTML

VITE_HUMANBEHAVIOR_API_KEY=your-api-key
VITE_HUMANBEHAVIOR_INGESTION_URL=https://ingest.humanbehavior.co

The wizard reference project uses Vite-style import.meta.env, so it uses VITE_ public env vars.

Bundled init in src/main.js

import { HumanBehaviorTracker } from "humanbehavior-js";

const apiKey = import.meta.env.VITE_HUMANBEHAVIOR_API_KEY;
if (apiKey) {
  HumanBehaviorTracker.init(apiKey, {
    ingestionUrl: import.meta.env.VITE_HUMANBEHAVIOR_INGESTION_URL,
  });
}

Reference src/main.js from HTML as your bundler expects:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Your app</title>
  </head>
  <body>
    <main id="app"></main>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>

CDN/manual static install

The published humanbehavior-js package declares unpkg and jsdelivr browser bundle entries and the browser entry exposes:

GlobalMeaning
window.HumanBehaviorTrackerTracker class
window.humanbehavior.init(apiKey, ingestionUrl?, options?)Convenience init function

Manual CDN example:

<script src="https://unpkg.com/humanbehavior-js@latest/packages/browser/dist/index.min.js"></script>
<script>
  window.humanbehavior.init("YOUR_API_KEY", undefined, {
    redactionStrategy: { mode: "visibility-first" },
  });
</script>

If you override ingestion with the CDN convenience function, the second positional argument is ingestionUrl:

<script>
  window.humanbehavior.init(
    "YOUR_API_KEY",
    "https://ingest.humanbehavior.co",
    { release: "1.2.3" }
  );
</script>

For npm imports, prefer HumanBehaviorTracker.init(apiKey, options) as shown in the SDK reference. The CDN init helper is a browser-bundle convenience.

Where to put it

Site typeRecommended placement
Vite HTMLsrc/main.js imported by index.html
Multi-page static site with shared templateShared layout/footer script
One-off static pageBefore </body> after the SDK bundle
Server-rendered templatesShared base template that every page includes

Initialize once per browser page load. Do not paste the snippet in every partial that can render multiple times.

Privacy

HTML pages often include forms. Configure redaction before sending traffic:

HumanBehaviorTracker.init(apiKey, {
  redactionStrategy: {
    mode: "privacy-first",
    unredactFields: ["[data-hb-visible]"],
  },
});

For CDN:

<script>
  window.humanbehavior.init("YOUR_API_KEY", undefined, {
    redactionStrategy: {
      mode: "privacy-first",
      unredactFields: ["[data-hb-visible]"],
    },
  });
</script>

Common pitfalls

PitfallSymptomFix
Using import in a non-module scriptBrowser syntax errorUse type="module" or CDN global
Missing VITE_ env prefix in bundled projectapiKey undefinedRename env var and restart bundler
Hardcoding key in a committed HTML fileKey leak in gitPrefer build-time env or server template injection
Loading CDN bundle after calling inithumanbehavior undefinedPut SDK script first
Expecting wizard to configure unbundled static hosting perfectlyEarly reject or needs-attentionUse manual CDN install

Wizard config summary

Wizard fieldValue
Integrationhtml
Package nameEmpty; usesPackageJson is false for detection
Env varsVITE_HUMANBEHAVIOR_API_KEY, VITE_HUMANBEHAVIOR_INGESTION_URL
Detectionindex.html, public/index.html, src/index.html
Reference filesindex.html, src/main.js

Verify

  1. Open the actual hosted page in a browser.
  2. Confirm the SDK script or module loads without console errors.
  3. Confirm /api/ingestion/events and /heartbeat return 2xx (init is not required).
  4. Click and navigate.
  5. Open Replays.

Full guide: Verify data is flowing.