HumanBehaviorTracker API

The main tracker class for recording user sessions and events.
How to find your Public API Key:
Flow: Project Home → Settings (on sidebar) → Public API Key
Where to find your Public API Key

Example screenshot – your actual API key will be different.

Initialization

HumanBehaviorTracker.init(apiKey, options?)

Static method to initialize the tracker with global persistence.
static init(
  apiKey: string, 
  options?: {
    redactFields?: string[];
  }
): HumanBehaviorTracker
Parameters:
  • apiKey (string): Your HumanBehavior API key
  • options (object, optional): Configuration options
    • redactFields (string[], optional): CSS selectors for fields to redact
Returns: HumanBehaviorTracker instance Example:
const tracker = HumanBehaviorTracker.init('your-api-key', {
  redactFields: ['input[type="password"]', '#email']
});

Core Methods

start()

Start recording user sessions and events.
async start(): Promise<void>
Example:
await tracker.start();

stop()

Stop recording and cleanup resources.
async stop(): Promise<void>
Example:
await tracker.stop();

addEvent(event)

Add a custom event to the recording queue.
async addEvent(event: any): Promise<void>
Parameters:
  • event (any): Event object to record
Example:
await tracker.addEvent({
  type: 'custom',
  data: { action: 'button_click' }
});

User Management

addUserInfo(userProperties)

Add user information for identification.
async addUserInfo(userProperties: Record<string, any>): Promise<void>
Parameters:
  • userProperties (object): User properties (email, name, etc.)
Example:
await tracker.addUserInfo({
  email: 'user@example.com',
  name: 'John Doe',
  userId: '12345'
});

auth(authFields)

Authenticate user using existing user data.
async auth(authFields: string[]): Promise<void>
Parameters:
  • authFields (string[]): Array of field names to check for existing users
Example:
await tracker.auth(['email', 'phoneNumber']);

Data Redaction

redact(options?)

Enable data redaction for sensitive fields.
async redact(options?: RedactionOptions): Promise<void>
Parameters:
  • options (RedactionOptions, optional): Redaction configuration
Example:
await tracker.redact({
  maskTextInputs: true,
  maskAllText: false
});

setRedactedFields(fields)

Set specific fields to be redacted.
setRedactedFields(fields: string[]): void
Parameters:
  • fields (string[]): Array of CSS selectors for fields to redact
Example:
tracker.setRedactedFields([
  'input[type="password"]',
  '#email-field',
  '.sensitive-data'
]);

isRedactionActive()

Check if redaction is currently active.
isRedactionActive(): boolean
Returns: boolean Example:
if (tracker.isRedactionActive()) {
  console.log('Redaction is enabled');
}

getRedactedFields()

Get the currently selected fields for redaction.
getRedactedFields(): string[]
Returns: string[] Example:
const fields = tracker.getRedactedFields();
console.log('Redacted fields:', fields);

User Information

getUserInfo()

Get comprehensive user information.
getUserInfo(): {
  endUserId: string | null;
  sessionId: string;
  isPreexistingUser: boolean;
  initialized: boolean;
}
Returns: User information object Example:
const userInfo = tracker.getUserInfo();
console.log('User ID:', userInfo.endUserId);
console.log('Session ID:', userInfo.sessionId);
console.log('Is existing user:', userInfo.isPreexistingUser);

getSessionId()

Get the current session ID.
getSessionId(): string
Returns: string Example:
const sessionId = tracker.getSessionId();
console.log('Current session:', sessionId);

getCurrentUrl()

Get the current URL being tracked.
getCurrentUrl(): string
Returns: string