Developer pages

Angular

Install HumanBehavior in Angular browser bootstrap with NG_APP env vars and SSR guards.

Angular has no built-in browser env-var prefix, so the shipped wizard uses the NG_APP_ convention and expects your Angular build tooling to expose those values to the browser bundle.

Wizard detection

The wizard detects Angular when it sees:

SignalDetails
@angular/core dependencyVersion read from package.json
angular.jsonAngular workspace fallback

The framework config deliberately uses NG_APP_HUMANBEHAVIOR_* env names. That convention commonly pairs with env tooling such as @ngx-env/builder, a custom define plugin, or deployment-time replacements.

Package

pnpm add humanbehavior-js

Environment variables

NG_APP_HUMANBEHAVIOR_API_KEY=your-api-key
NG_APP_HUMANBEHAVIOR_INGESTION_URL=https://ingest.humanbehavior.co

These names do not magically exist in Angular. Make sure your build exposes them to browser code.

Browser bootstrap example

In a standalone Angular app, initialize in src/main.ts:

import { bootstrapApplication } from "@angular/platform-browser";
import { HumanBehaviorTracker } from "humanbehavior-js";
import { AppComponent } from "./app/app.component";
import { appConfig } from "./app/app.config";

declare const process: { env: Record<string, string | undefined> };

if (typeof window !== "undefined") {
  const apiKey = process.env.NG_APP_HUMANBEHAVIOR_API_KEY;
  if (apiKey) {
    HumanBehaviorTracker.init(apiKey, {
      ingestionUrl: process.env.NG_APP_HUMANBEHAVIOR_INGESTION_URL,
    });
  }
}

bootstrapApplication(AppComponent, appConfig).catch((err) =>
  console.error(err),
);

The typeof window guard prevents accidental execution if this module is evaluated by Angular Universal or another SSR setup.

NgModule bootstrap variant

If your app uses platformBrowserDynamic:

import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
import { HumanBehaviorTracker } from "humanbehavior-js";
import { AppModule } from "./app/app.module";

declare const process: { env: Record<string, string | undefined> };

if (typeof window !== "undefined") {
  const apiKey = process.env.NG_APP_HUMANBEHAVIOR_API_KEY;
  if (apiKey) {
    HumanBehaviorTracker.init(apiKey, {
      ingestionUrl: process.env.NG_APP_HUMANBEHAVIOR_INGESTION_URL,
    });
  }
}

platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .catch((err) => console.error(err));

Build tooling requirement

Angular projects differ. Pick the approach your repo already uses:

ApproachWhat to check
@ngx-env/builderNG_APP_* values are available as process.env.NG_APP_*
Custom webpack/defineValues are replaced at build time
environment.ts filesMap values there, then pass them to HumanBehaviorTracker.init
Runtime config JSONFetch/load config before calling init

The docs do not claim Angular ships a native env loader. The wizard's NG_APP_ names are a convention, not an Angular platform feature.

Router behavior

Angular router navigation uses browser history. The SDK's automatic navigation capture handles normal route transitions.

If you have unusual routing, you can call trackPageView() from a router event subscription:

const tracker = HumanBehaviorTracker.init(apiKey);

router.events.subscribe((event) => {
  if (event instanceof NavigationEnd) {
    void tracker.trackPageView();
  }
});

Most apps do not need this manual hook.

SSR / Angular Universal

File / contextStatus
Browser src/main.tsRecommended
main.server.tsDo not initialize
Server app moduleDo not initialize
Component constructorsAvoid; can run many times
App initializer with browser guardAcceptable if it runs once

Options example

HumanBehaviorTracker.init(apiKey, {
  ingestionUrl: process.env.NG_APP_HUMANBEHAVIOR_INGESTION_URL,
  environment: process.env.NG_APP_ENVIRONMENT,
  release: process.env.NG_APP_VERSION,
  redactionStrategy: { mode: "visibility-first" },
});

Common pitfalls

PitfallSymptomFix
process is not definedBuild/runtime errorUse your repo's env tooling or environment.ts
Init in server bundlewindow/DOM errorsGuard with typeof window and use browser entry
Multiple Angular bootstrapsDuplicate init attemptsKeep one shared init
No replay after deployEnv replaced at build time with empty valueInspect built env config and network requests

Wizard config summary

Wizard fieldValue
Integrationangular
Package signal@angular/core
File signalangular.json
Env varsNG_APP_HUMANBEHAVIOR_API_KEY, NG_APP_HUMANBEHAVIOR_INGESTION_URL
Reference entrysrc/main.ts

Verify

  1. Rebuild/restart after env changes.
  2. Open the Angular app in a browser.
  3. Confirm ingestion requests return 2xx.
  4. Navigate between Angular routes.
  5. Check Replays and Dashboard.

Full checklist: Verify data is flowing.