humanbehavior-js
Version:
SDK for HumanBehavior session and event recording
79 lines (71 loc) • 2.44 kB
text/typescript
import { HumanBehaviorTracker } from '../index.js';
// Angular NgModule for legacy Angular applications
export class HumanBehaviorModule {
static forRoot(config: {
apiKey: string;
ingestionUrl?: string;
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
redactFields?: string[];
suppressConsoleErrors?: boolean;
recordCanvas?: boolean; // Enable canvas recording with PostHog-style protection
}) {
return {
ngModule: HumanBehaviorModule,
providers: [
{
provide: 'HUMANBEHAVIOR_API_KEY',
useValue: config.apiKey
},
{
provide: HumanBehaviorTracker,
useFactory: (apiKey: string) => {
return HumanBehaviorTracker.init(apiKey, {
ingestionUrl: config.ingestionUrl,
logLevel: config.logLevel,
redactFields: config.redactFields,
suppressConsoleErrors: config.suppressConsoleErrors,
recordCanvas: config.recordCanvas, // Pass canvas recording option
});
},
deps: ['HUMANBEHAVIOR_API_KEY']
}
]
};
}
}
// Angular service for dependency injection
export class HumanBehaviorService {
private tracker: HumanBehaviorTracker;
constructor(apiKey: string, options?: {
ingestionUrl?: string;
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
redactFields?: string[];
suppressConsoleErrors?: boolean;
recordCanvas?: boolean; // Enable canvas recording with PostHog-style protection
}) {
this.tracker = HumanBehaviorTracker.init(apiKey, options);
}
// Expose core tracker methods
identifyUser(userProperties: Record<string, any>) {
return this.tracker.identifyUser({ userProperties });
}
getSessionId() {
return this.tracker.getSessionId();
}
setRedactedFields(fields: string[]) {
return this.tracker.setRedactedFields(fields);
}
getRedactedFields() {
return this.tracker.getRedactedFields();
}
}
// Helper function for standalone Angular initialization
export function initializeHumanBehavior(apiKey: string, options?: {
ingestionUrl?: string;
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
redactFields?: string[];
suppressConsoleErrors?: boolean;
recordCanvas?: boolean; // Enable canvas recording with PostHog-style protection
}): HumanBehaviorTracker {
return HumanBehaviorTracker.init(apiKey, options);
}