humanbehavior-js 0.4.15 → 0.4.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/wizard/index.cjs +6 -8
- package/dist/cjs/wizard/index.cjs.map +1 -1
- package/dist/cli/ai-auto-install.js +6 -8
- package/dist/cli/ai-auto-install.js.map +1 -1
- package/dist/esm/wizard/index.js +6 -8
- package/dist/esm/wizard/index.js.map +1 -1
- package/package/WIZARD_USAGE_GUIDE.md +381 -0
- package/package/canvas-recording-demo.html +143 -0
- package/package/clean-console-demo.html +39 -0
- package/package/dist/cjs/angular/index.cjs +14354 -0
- package/package/dist/cjs/angular/index.cjs.map +1 -0
- package/package/dist/cjs/index.cjs +14323 -0
- package/package/dist/cjs/index.cjs.map +1 -0
- package/package/dist/cjs/install-wizard.cjs +1530 -0
- package/package/dist/cjs/install-wizard.cjs.map +1 -0
- package/package/dist/cjs/react/index.cjs +14478 -0
- package/package/dist/cjs/react/index.cjs.map +1 -0
- package/package/dist/cjs/remix/index.cjs +14452 -0
- package/package/dist/cjs/remix/index.cjs.map +1 -0
- package/package/dist/cjs/svelte/index.cjs +14308 -0
- package/package/dist/cjs/svelte/index.cjs.map +1 -0
- package/package/dist/cjs/vue/index.cjs +14317 -0
- package/package/dist/cjs/vue/index.cjs.map +1 -0
- package/package/dist/cjs/wizard/index.cjs +3446 -0
- package/package/dist/cjs/wizard/index.cjs.map +1 -0
- package/package/dist/cli/ai-auto-install.cjs +57161 -0
- package/package/dist/cli/ai-auto-install.cjs.map +1 -0
- package/package/dist/cli/ai-auto-install.js +1969 -0
- package/package/dist/cli/ai-auto-install.js.map +1 -0
- package/package/dist/cli/auto-install.cjs +56352 -0
- package/package/dist/cli/auto-install.cjs.map +1 -0
- package/package/dist/cli/auto-install.js +1957 -0
- package/package/dist/cli/auto-install.js.map +1 -0
- package/package/dist/esm/angular/index.js +14350 -0
- package/package/dist/esm/angular/index.js.map +1 -0
- package/package/dist/esm/index.js +14309 -0
- package/package/dist/esm/index.js.map +1 -0
- package/package/dist/esm/install-wizard.js +1507 -0
- package/package/dist/esm/install-wizard.js.map +1 -0
- package/package/dist/esm/react/index.js +14472 -0
- package/package/dist/esm/react/index.js.map +1 -0
- package/package/dist/esm/remix/index.js +14448 -0
- package/package/dist/esm/remix/index.js.map +1 -0
- package/package/dist/esm/svelte/index.js +14306 -0
- package/package/dist/esm/svelte/index.js.map +1 -0
- package/package/dist/esm/vue/index.js +14315 -0
- package/package/dist/esm/vue/index.js.map +1 -0
- package/package/dist/esm/wizard/index.js +3415 -0
- package/package/dist/esm/wizard/index.js.map +1 -0
- package/package/dist/index.min.js +2 -0
- package/package/dist/index.min.js.map +1 -0
- package/package/dist/types/angular/index.d.ts +267 -0
- package/package/dist/types/index.d.ts +373 -0
- package/package/dist/types/install-wizard.d.ts +156 -0
- package/package/dist/types/react/index.d.ts +255 -0
- package/package/dist/types/remix/index.d.ts +246 -0
- package/package/dist/types/svelte/index.d.ts +232 -0
- package/package/dist/types/vue/index.d.ts +15 -0
- package/package/dist/types/wizard/index.d.ts +523 -0
- package/package/package.json +105 -0
- package/package/readme.md +281 -0
- package/package/rollup.config.js +422 -0
- package/package/simple-demo.html +26 -0
- package/package/simple-spa.html +838 -0
- package/package/src/angular/index.ts +79 -0
- package/package/src/api.ts +376 -0
- package/package/src/index.ts +28 -0
- package/package/src/react/AutoInstallWizard.tsx +557 -0
- package/package/src/react/browser.ts +8 -0
- package/package/src/react/index.tsx +308 -0
- package/package/src/redact.ts +521 -0
- package/package/src/remix/index.ts +16 -0
- package/package/src/svelte/index.ts +14 -0
- package/package/src/tracker.ts +1319 -0
- package/package/src/types/clack.d.ts +31 -0
- package/package/src/utils/logger.ts +144 -0
- package/package/src/vue/index.ts +29 -0
- package/package/src/wizard/README.md +114 -0
- package/package/src/wizard/ai/ai-install-wizard.ts +897 -0
- package/package/src/wizard/ai/manual-framework-wizard.ts +238 -0
- package/package/src/wizard/cli/ai-auto-install.ts +243 -0
- package/package/src/wizard/cli/auto-install.ts +224 -0
- package/package/src/wizard/core/install-wizard.ts +1744 -0
- package/package/src/wizard/index.ts +23 -0
- package/package/src/wizard/services/centralized-ai-service.ts +668 -0
- package/package/src/wizard/services/remote-ai-service.ts +240 -0
- package/package/tsconfig.json +24 -0
- package/package.json +1 -1
- package/src/wizard/cli/ai-auto-install.ts +4 -6
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HumanBehavior SDK Auto-Installation Wizard
|
|
3
|
+
*
|
|
4
|
+
* This wizard automatically detects the user's framework and modifies their codebase
|
|
5
|
+
* to integrate the SDK with minimal user intervention.
|
|
6
|
+
*/
|
|
7
|
+
interface FrameworkInfo {
|
|
8
|
+
name: string;
|
|
9
|
+
type: 'react' | 'vue' | 'angular' | 'svelte' | 'nextjs' | 'nuxt' | 'remix' | 'vanilla' | 'astro' | 'gatsby' | 'node' | 'auto';
|
|
10
|
+
bundler?: 'vite' | 'webpack' | 'esbuild' | 'rollup';
|
|
11
|
+
packageManager?: 'npm' | 'yarn' | 'pnpm';
|
|
12
|
+
hasTypeScript?: boolean;
|
|
13
|
+
hasRouter?: boolean;
|
|
14
|
+
projectRoot?: string;
|
|
15
|
+
version?: string;
|
|
16
|
+
majorVersion?: number;
|
|
17
|
+
features?: {
|
|
18
|
+
hasReact18?: boolean;
|
|
19
|
+
hasVue3?: boolean;
|
|
20
|
+
hasNuxt3?: boolean;
|
|
21
|
+
hasAngularStandalone?: boolean;
|
|
22
|
+
hasNextAppRouter?: boolean;
|
|
23
|
+
hasSvelteKit?: boolean;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface CodeModification {
|
|
27
|
+
filePath: string;
|
|
28
|
+
action: 'create' | 'modify' | 'append';
|
|
29
|
+
content: string;
|
|
30
|
+
description: string;
|
|
31
|
+
}
|
|
32
|
+
interface InstallationResult {
|
|
33
|
+
success: boolean;
|
|
34
|
+
framework: FrameworkInfo;
|
|
35
|
+
modifications: CodeModification[];
|
|
36
|
+
errors: string[];
|
|
37
|
+
nextSteps: string[];
|
|
38
|
+
}
|
|
39
|
+
declare class AutoInstallationWizard {
|
|
40
|
+
protected apiKey: string;
|
|
41
|
+
protected projectRoot: string;
|
|
42
|
+
protected framework: FrameworkInfo | null;
|
|
43
|
+
constructor(apiKey: string, projectRoot?: string);
|
|
44
|
+
/**
|
|
45
|
+
* Simple version comparison utility
|
|
46
|
+
*/
|
|
47
|
+
private compareVersions;
|
|
48
|
+
private isVersionGte;
|
|
49
|
+
private getMajorVersion;
|
|
50
|
+
/**
|
|
51
|
+
* Main installation method - detects framework and auto-installs
|
|
52
|
+
*/
|
|
53
|
+
install(): Promise<InstallationResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Detect the current framework and project setup
|
|
56
|
+
*/
|
|
57
|
+
detectFramework(): Promise<FrameworkInfo>;
|
|
58
|
+
/**
|
|
59
|
+
* Install the SDK package
|
|
60
|
+
*/
|
|
61
|
+
protected installPackage(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Generate code modifications based on framework
|
|
64
|
+
*/
|
|
65
|
+
protected generateModifications(): Promise<CodeModification[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Generate React-specific modifications
|
|
68
|
+
*/
|
|
69
|
+
private generateReactModifications;
|
|
70
|
+
/**
|
|
71
|
+
* Generate Next.js-specific modifications
|
|
72
|
+
*/
|
|
73
|
+
private generateNextJSModifications;
|
|
74
|
+
/**
|
|
75
|
+
* Generate Astro-specific modifications
|
|
76
|
+
*/
|
|
77
|
+
private generateAstroModifications;
|
|
78
|
+
/**
|
|
79
|
+
* Generate Nuxt-specific modifications
|
|
80
|
+
*/
|
|
81
|
+
private generateNuxtModifications;
|
|
82
|
+
/**
|
|
83
|
+
* Generate Remix-specific modifications
|
|
84
|
+
*/
|
|
85
|
+
private generateRemixModifications;
|
|
86
|
+
/**
|
|
87
|
+
* Generate Vue-specific modifications
|
|
88
|
+
*/
|
|
89
|
+
private generateVueModifications;
|
|
90
|
+
/**
|
|
91
|
+
* Generate Angular-specific modifications
|
|
92
|
+
*/
|
|
93
|
+
private generateAngularModifications;
|
|
94
|
+
/**
|
|
95
|
+
* Generate Svelte-specific modifications
|
|
96
|
+
*/
|
|
97
|
+
private generateSvelteModifications;
|
|
98
|
+
/**
|
|
99
|
+
* Generate vanilla JS/TS modifications
|
|
100
|
+
*/
|
|
101
|
+
private generateVanillaModifications;
|
|
102
|
+
/**
|
|
103
|
+
* Generate Gatsby-specific modifications
|
|
104
|
+
*/
|
|
105
|
+
private generateGatsbyModifications;
|
|
106
|
+
/**
|
|
107
|
+
* Apply modifications to the codebase
|
|
108
|
+
*/
|
|
109
|
+
protected applyModifications(modifications: CodeModification[]): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Generate next steps for the user
|
|
112
|
+
*/
|
|
113
|
+
private generateNextSteps;
|
|
114
|
+
private findReactAppFile;
|
|
115
|
+
private findVueMainFile;
|
|
116
|
+
private findSvelteMainFile;
|
|
117
|
+
private findHTMLFile;
|
|
118
|
+
private injectReactProvider;
|
|
119
|
+
private injectNextJSAppRouter;
|
|
120
|
+
private injectNextJSPagesRouter;
|
|
121
|
+
private injectRemixProvider;
|
|
122
|
+
private injectVuePlugin;
|
|
123
|
+
private injectAngularModule;
|
|
124
|
+
private injectAngularStandaloneInit;
|
|
125
|
+
private injectSvelteStore;
|
|
126
|
+
private injectSvelteKitLayout;
|
|
127
|
+
private injectVanillaScript;
|
|
128
|
+
/**
|
|
129
|
+
* Inject Astro layout with HumanBehavior component
|
|
130
|
+
*/
|
|
131
|
+
private injectAstroLayout;
|
|
132
|
+
private injectNuxtConfig;
|
|
133
|
+
private injectGatsbyLayout;
|
|
134
|
+
private injectGatsbyBrowser;
|
|
135
|
+
/**
|
|
136
|
+
* Helper method to find the best environment file for a framework
|
|
137
|
+
*/
|
|
138
|
+
private findBestEnvFile;
|
|
139
|
+
/**
|
|
140
|
+
* Helper method to create or append to environment files
|
|
141
|
+
*/
|
|
142
|
+
private createEnvironmentModification;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Browser-based auto-installation wizard
|
|
146
|
+
*/
|
|
147
|
+
declare class BrowserAutoInstallationWizard {
|
|
148
|
+
private apiKey;
|
|
149
|
+
constructor(apiKey: string);
|
|
150
|
+
install(): Promise<InstallationResult>;
|
|
151
|
+
private detectFramework;
|
|
152
|
+
private generateBrowserModifications;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export { AutoInstallationWizard, BrowserAutoInstallationWizard };
|
|
156
|
+
export type { CodeModification, FrameworkInfo, InstallationResult };
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface RedactionOptions {
|
|
4
|
+
redactedText?: string;
|
|
5
|
+
excludeSelectors?: string[];
|
|
6
|
+
userFields?: string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
HumanBehaviorTracker: typeof HumanBehaviorTracker;
|
|
12
|
+
__humanBehaviorGlobalTracker?: HumanBehaviorTracker;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
declare class HumanBehaviorTracker {
|
|
16
|
+
private eventIngestionQueue;
|
|
17
|
+
private sessionId;
|
|
18
|
+
private userProperties;
|
|
19
|
+
private isProcessing;
|
|
20
|
+
private flushInterval;
|
|
21
|
+
private readonly FLUSH_INTERVAL_MS;
|
|
22
|
+
private api;
|
|
23
|
+
private endUserId;
|
|
24
|
+
private apiKey;
|
|
25
|
+
private initialized;
|
|
26
|
+
initializationPromise: Promise<void> | null;
|
|
27
|
+
private redactionManager;
|
|
28
|
+
private originalConsole;
|
|
29
|
+
private consoleTrackingEnabled;
|
|
30
|
+
navigationTrackingEnabled: boolean;
|
|
31
|
+
private currentUrl;
|
|
32
|
+
private previousUrl;
|
|
33
|
+
private originalPushState;
|
|
34
|
+
private originalReplaceState;
|
|
35
|
+
private navigationListeners;
|
|
36
|
+
private _connectionBlocked;
|
|
37
|
+
private recordInstance;
|
|
38
|
+
private sessionStartTime;
|
|
39
|
+
private rrwebRecord;
|
|
40
|
+
private fullSnapshotTimeout;
|
|
41
|
+
private recordCanvas;
|
|
42
|
+
/**
|
|
43
|
+
* Initialize the HumanBehavior tracker
|
|
44
|
+
* This is the main entry point - call this once per page
|
|
45
|
+
*/
|
|
46
|
+
static init(apiKey: string, options?: {
|
|
47
|
+
ingestionUrl?: string;
|
|
48
|
+
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
49
|
+
redactFields?: string[];
|
|
50
|
+
enableAutomaticTracking?: boolean;
|
|
51
|
+
suppressConsoleErrors?: boolean;
|
|
52
|
+
recordCanvas?: boolean;
|
|
53
|
+
automaticTrackingOptions?: {
|
|
54
|
+
trackButtons?: boolean;
|
|
55
|
+
trackLinks?: boolean;
|
|
56
|
+
trackForms?: boolean;
|
|
57
|
+
includeText?: boolean;
|
|
58
|
+
includeClasses?: boolean;
|
|
59
|
+
};
|
|
60
|
+
}): HumanBehaviorTracker;
|
|
61
|
+
constructor(apiKey: string | undefined, ingestionUrl?: string);
|
|
62
|
+
private init;
|
|
63
|
+
private ensureInitialized;
|
|
64
|
+
/**
|
|
65
|
+
* Setup navigation event tracking for SPA navigation
|
|
66
|
+
*/
|
|
67
|
+
private setupNavigationTracking;
|
|
68
|
+
/**
|
|
69
|
+
* Track navigation events and send custom events
|
|
70
|
+
*/
|
|
71
|
+
trackNavigationEvent(type: string, fromUrl: string, toUrl: string): Promise<void>;
|
|
72
|
+
trackPageView(url?: string): Promise<void>;
|
|
73
|
+
customEvent(eventName: string, properties?: Record<string, any>): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Setup automatic tracking for buttons, links, and forms
|
|
76
|
+
*/
|
|
77
|
+
private setupAutomaticTracking;
|
|
78
|
+
/**
|
|
79
|
+
* Setup automatic button tracking
|
|
80
|
+
*/
|
|
81
|
+
private setupAutomaticButtonTracking;
|
|
82
|
+
/**
|
|
83
|
+
* Setup automatic link tracking
|
|
84
|
+
*/
|
|
85
|
+
private setupAutomaticLinkTracking;
|
|
86
|
+
/**
|
|
87
|
+
* Setup automatic form tracking
|
|
88
|
+
*/
|
|
89
|
+
private setupAutomaticFormTracking;
|
|
90
|
+
/**
|
|
91
|
+
* Cleanup navigation tracking
|
|
92
|
+
*/
|
|
93
|
+
private cleanupNavigationTracking;
|
|
94
|
+
static logToStorage(message: string): void;
|
|
95
|
+
/**
|
|
96
|
+
* Configure logging behavior for the SDK
|
|
97
|
+
* @param config Logger configuration options
|
|
98
|
+
*/
|
|
99
|
+
static configureLogging(config: {
|
|
100
|
+
level?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
101
|
+
enableConsole?: boolean;
|
|
102
|
+
enableStorage?: boolean;
|
|
103
|
+
}): void;
|
|
104
|
+
/**
|
|
105
|
+
* Enable console event tracking
|
|
106
|
+
*/
|
|
107
|
+
enableConsoleTracking(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Disable console event tracking
|
|
110
|
+
*/
|
|
111
|
+
disableConsoleTracking(): void;
|
|
112
|
+
private trackConsoleEvent;
|
|
113
|
+
private setupPageUnloadHandler;
|
|
114
|
+
viewLogs(): void;
|
|
115
|
+
/**
|
|
116
|
+
* Add user identification information to the tracker
|
|
117
|
+
* If userId is not provided, will use userProperties.email as the userId (if present)
|
|
118
|
+
*/
|
|
119
|
+
identifyUser({ userProperties }: {
|
|
120
|
+
userProperties: Record<string, any>;
|
|
121
|
+
}): Promise<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Get current user attributes
|
|
124
|
+
*/
|
|
125
|
+
getUserAttributes(): Record<string, any>;
|
|
126
|
+
start(): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Manually trigger a FullSnapshot (for navigation events)
|
|
129
|
+
* Delays snapshot to avoid capturing mid-animation states
|
|
130
|
+
*/
|
|
131
|
+
private takeFullSnapshot;
|
|
132
|
+
stop(): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Add an event to the ingestion queue
|
|
135
|
+
* Events are sent directly without processing to avoid corruption
|
|
136
|
+
*/
|
|
137
|
+
addEvent(event: any): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Flush events to the ingestion server
|
|
140
|
+
* Events are sent in chunks to handle large payloads efficiently
|
|
141
|
+
*/
|
|
142
|
+
private flush;
|
|
143
|
+
private setCookie;
|
|
144
|
+
getCookie(name: string): string | null;
|
|
145
|
+
/**
|
|
146
|
+
* Delete a cookie by setting its expiration date to the past
|
|
147
|
+
* @param name The name of the cookie to delete
|
|
148
|
+
*/
|
|
149
|
+
private deleteCookie;
|
|
150
|
+
/**
|
|
151
|
+
* Clear user data and reset session when user signs out of the site
|
|
152
|
+
* This should be called when a user logs out of your application to prevent
|
|
153
|
+
* data contamination between different users
|
|
154
|
+
*/
|
|
155
|
+
logout(): void;
|
|
156
|
+
/**
|
|
157
|
+
* Start redaction functionality for sensitive input fields
|
|
158
|
+
* @param options Optional configuration for redaction behavior
|
|
159
|
+
*/
|
|
160
|
+
redact(options?: RedactionOptions): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Set specific fields to be redacted during session recording
|
|
163
|
+
* Uses rrweb's built-in masking instead of custom redaction processing
|
|
164
|
+
* @param fields Array of CSS selectors for fields to redact (e.g., ['input[type="password"]', '#email-field'])
|
|
165
|
+
*/
|
|
166
|
+
setRedactedFields(fields: string[]): void;
|
|
167
|
+
private restartWithNewRedaction;
|
|
168
|
+
/**
|
|
169
|
+
* Check if redaction is currently active
|
|
170
|
+
*/
|
|
171
|
+
isRedactionActive(): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Get the currently selected fields for redaction
|
|
174
|
+
*/
|
|
175
|
+
getRedactedFields(): string[];
|
|
176
|
+
/**
|
|
177
|
+
* Get the current session ID
|
|
178
|
+
*/
|
|
179
|
+
getSessionId(): string;
|
|
180
|
+
/**
|
|
181
|
+
* Get the current URL being tracked
|
|
182
|
+
*/
|
|
183
|
+
getCurrentUrl(): string;
|
|
184
|
+
/**
|
|
185
|
+
* Get current snapshot frequency info
|
|
186
|
+
* Uses configured values (5 minutes, 1000 events)
|
|
187
|
+
*/
|
|
188
|
+
getSnapshotFrequencyInfo(): {
|
|
189
|
+
sessionDuration: number;
|
|
190
|
+
currentInterval: number;
|
|
191
|
+
currentThreshold: number;
|
|
192
|
+
phase: string;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Test if the tracker can reach the ingestion server
|
|
196
|
+
*/
|
|
197
|
+
testConnection(): Promise<{
|
|
198
|
+
success: boolean;
|
|
199
|
+
error?: string;
|
|
200
|
+
}>;
|
|
201
|
+
/**
|
|
202
|
+
* Get connection status and recommendations
|
|
203
|
+
*/
|
|
204
|
+
getConnectionStatus(): {
|
|
205
|
+
blocked: boolean;
|
|
206
|
+
recommendations: string[];
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Check if the current user is a preexisting user
|
|
210
|
+
* Returns true if the user has an existing endUserId cookie from a previous session
|
|
211
|
+
*/
|
|
212
|
+
isPreexistingUser(): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Get user information including whether they are preexisting
|
|
215
|
+
*/
|
|
216
|
+
getUserInfo(): {
|
|
217
|
+
endUserId: string | null;
|
|
218
|
+
sessionId: string;
|
|
219
|
+
isPreexistingUser: boolean;
|
|
220
|
+
initialized: boolean;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
interface HumanBehaviorProviderProps {
|
|
225
|
+
apiKey?: string;
|
|
226
|
+
client?: HumanBehaviorTracker;
|
|
227
|
+
children: ReactNode;
|
|
228
|
+
options?: {
|
|
229
|
+
ingestionUrl?: string;
|
|
230
|
+
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
231
|
+
redactFields?: string[];
|
|
232
|
+
suppressConsoleErrors?: boolean;
|
|
233
|
+
recordCanvas?: boolean;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
declare const HumanBehaviorProvider: ({ apiKey, client, children, options }: HumanBehaviorProviderProps) => React.JSX.Element;
|
|
237
|
+
declare const useHumanBehavior: () => HumanBehaviorTracker;
|
|
238
|
+
declare const useRedaction: () => {
|
|
239
|
+
setRedactedFields: (fields: string[]) => void;
|
|
240
|
+
isRedactionActive: () => boolean;
|
|
241
|
+
getRedactedFields: () => string[];
|
|
242
|
+
};
|
|
243
|
+
declare const useUserTracking: () => {
|
|
244
|
+
identifyUser: ({ userProperties }: {
|
|
245
|
+
userProperties: Record<string, any>;
|
|
246
|
+
}) => Promise<{
|
|
247
|
+
success: boolean;
|
|
248
|
+
error?: undefined;
|
|
249
|
+
} | {
|
|
250
|
+
success: boolean;
|
|
251
|
+
error: unknown;
|
|
252
|
+
}>;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
export { HumanBehaviorProvider, HumanBehaviorTracker, useHumanBehavior, useRedaction, useUserTracking };
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { LoaderFunctionArgs } from '@remix-run/node';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface RedactionOptions {
|
|
5
|
+
redactedText?: string;
|
|
6
|
+
excludeSelectors?: string[];
|
|
7
|
+
userFields?: string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
interface Window {
|
|
12
|
+
HumanBehaviorTracker: typeof HumanBehaviorTracker;
|
|
13
|
+
__humanBehaviorGlobalTracker?: HumanBehaviorTracker;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
declare class HumanBehaviorTracker {
|
|
17
|
+
private eventIngestionQueue;
|
|
18
|
+
private sessionId;
|
|
19
|
+
private userProperties;
|
|
20
|
+
private isProcessing;
|
|
21
|
+
private flushInterval;
|
|
22
|
+
private readonly FLUSH_INTERVAL_MS;
|
|
23
|
+
private api;
|
|
24
|
+
private endUserId;
|
|
25
|
+
private apiKey;
|
|
26
|
+
private initialized;
|
|
27
|
+
initializationPromise: Promise<void> | null;
|
|
28
|
+
private redactionManager;
|
|
29
|
+
private originalConsole;
|
|
30
|
+
private consoleTrackingEnabled;
|
|
31
|
+
navigationTrackingEnabled: boolean;
|
|
32
|
+
private currentUrl;
|
|
33
|
+
private previousUrl;
|
|
34
|
+
private originalPushState;
|
|
35
|
+
private originalReplaceState;
|
|
36
|
+
private navigationListeners;
|
|
37
|
+
private _connectionBlocked;
|
|
38
|
+
private recordInstance;
|
|
39
|
+
private sessionStartTime;
|
|
40
|
+
private rrwebRecord;
|
|
41
|
+
private fullSnapshotTimeout;
|
|
42
|
+
private recordCanvas;
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the HumanBehavior tracker
|
|
45
|
+
* This is the main entry point - call this once per page
|
|
46
|
+
*/
|
|
47
|
+
static init(apiKey: string, options?: {
|
|
48
|
+
ingestionUrl?: string;
|
|
49
|
+
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
50
|
+
redactFields?: string[];
|
|
51
|
+
enableAutomaticTracking?: boolean;
|
|
52
|
+
suppressConsoleErrors?: boolean;
|
|
53
|
+
recordCanvas?: boolean;
|
|
54
|
+
automaticTrackingOptions?: {
|
|
55
|
+
trackButtons?: boolean;
|
|
56
|
+
trackLinks?: boolean;
|
|
57
|
+
trackForms?: boolean;
|
|
58
|
+
includeText?: boolean;
|
|
59
|
+
includeClasses?: boolean;
|
|
60
|
+
};
|
|
61
|
+
}): HumanBehaviorTracker;
|
|
62
|
+
constructor(apiKey: string | undefined, ingestionUrl?: string);
|
|
63
|
+
private init;
|
|
64
|
+
private ensureInitialized;
|
|
65
|
+
/**
|
|
66
|
+
* Setup navigation event tracking for SPA navigation
|
|
67
|
+
*/
|
|
68
|
+
private setupNavigationTracking;
|
|
69
|
+
/**
|
|
70
|
+
* Track navigation events and send custom events
|
|
71
|
+
*/
|
|
72
|
+
trackNavigationEvent(type: string, fromUrl: string, toUrl: string): Promise<void>;
|
|
73
|
+
trackPageView(url?: string): Promise<void>;
|
|
74
|
+
customEvent(eventName: string, properties?: Record<string, any>): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Setup automatic tracking for buttons, links, and forms
|
|
77
|
+
*/
|
|
78
|
+
private setupAutomaticTracking;
|
|
79
|
+
/**
|
|
80
|
+
* Setup automatic button tracking
|
|
81
|
+
*/
|
|
82
|
+
private setupAutomaticButtonTracking;
|
|
83
|
+
/**
|
|
84
|
+
* Setup automatic link tracking
|
|
85
|
+
*/
|
|
86
|
+
private setupAutomaticLinkTracking;
|
|
87
|
+
/**
|
|
88
|
+
* Setup automatic form tracking
|
|
89
|
+
*/
|
|
90
|
+
private setupAutomaticFormTracking;
|
|
91
|
+
/**
|
|
92
|
+
* Cleanup navigation tracking
|
|
93
|
+
*/
|
|
94
|
+
private cleanupNavigationTracking;
|
|
95
|
+
static logToStorage(message: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Configure logging behavior for the SDK
|
|
98
|
+
* @param config Logger configuration options
|
|
99
|
+
*/
|
|
100
|
+
static configureLogging(config: {
|
|
101
|
+
level?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
102
|
+
enableConsole?: boolean;
|
|
103
|
+
enableStorage?: boolean;
|
|
104
|
+
}): void;
|
|
105
|
+
/**
|
|
106
|
+
* Enable console event tracking
|
|
107
|
+
*/
|
|
108
|
+
enableConsoleTracking(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Disable console event tracking
|
|
111
|
+
*/
|
|
112
|
+
disableConsoleTracking(): void;
|
|
113
|
+
private trackConsoleEvent;
|
|
114
|
+
private setupPageUnloadHandler;
|
|
115
|
+
viewLogs(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Add user identification information to the tracker
|
|
118
|
+
* If userId is not provided, will use userProperties.email as the userId (if present)
|
|
119
|
+
*/
|
|
120
|
+
identifyUser({ userProperties }: {
|
|
121
|
+
userProperties: Record<string, any>;
|
|
122
|
+
}): Promise<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Get current user attributes
|
|
125
|
+
*/
|
|
126
|
+
getUserAttributes(): Record<string, any>;
|
|
127
|
+
start(): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Manually trigger a FullSnapshot (for navigation events)
|
|
130
|
+
* Delays snapshot to avoid capturing mid-animation states
|
|
131
|
+
*/
|
|
132
|
+
private takeFullSnapshot;
|
|
133
|
+
stop(): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Add an event to the ingestion queue
|
|
136
|
+
* Events are sent directly without processing to avoid corruption
|
|
137
|
+
*/
|
|
138
|
+
addEvent(event: any): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Flush events to the ingestion server
|
|
141
|
+
* Events are sent in chunks to handle large payloads efficiently
|
|
142
|
+
*/
|
|
143
|
+
private flush;
|
|
144
|
+
private setCookie;
|
|
145
|
+
getCookie(name: string): string | null;
|
|
146
|
+
/**
|
|
147
|
+
* Delete a cookie by setting its expiration date to the past
|
|
148
|
+
* @param name The name of the cookie to delete
|
|
149
|
+
*/
|
|
150
|
+
private deleteCookie;
|
|
151
|
+
/**
|
|
152
|
+
* Clear user data and reset session when user signs out of the site
|
|
153
|
+
* This should be called when a user logs out of your application to prevent
|
|
154
|
+
* data contamination between different users
|
|
155
|
+
*/
|
|
156
|
+
logout(): void;
|
|
157
|
+
/**
|
|
158
|
+
* Start redaction functionality for sensitive input fields
|
|
159
|
+
* @param options Optional configuration for redaction behavior
|
|
160
|
+
*/
|
|
161
|
+
redact(options?: RedactionOptions): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Set specific fields to be redacted during session recording
|
|
164
|
+
* Uses rrweb's built-in masking instead of custom redaction processing
|
|
165
|
+
* @param fields Array of CSS selectors for fields to redact (e.g., ['input[type="password"]', '#email-field'])
|
|
166
|
+
*/
|
|
167
|
+
setRedactedFields(fields: string[]): void;
|
|
168
|
+
private restartWithNewRedaction;
|
|
169
|
+
/**
|
|
170
|
+
* Check if redaction is currently active
|
|
171
|
+
*/
|
|
172
|
+
isRedactionActive(): boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Get the currently selected fields for redaction
|
|
175
|
+
*/
|
|
176
|
+
getRedactedFields(): string[];
|
|
177
|
+
/**
|
|
178
|
+
* Get the current session ID
|
|
179
|
+
*/
|
|
180
|
+
getSessionId(): string;
|
|
181
|
+
/**
|
|
182
|
+
* Get the current URL being tracked
|
|
183
|
+
*/
|
|
184
|
+
getCurrentUrl(): string;
|
|
185
|
+
/**
|
|
186
|
+
* Get current snapshot frequency info
|
|
187
|
+
* Uses configured values (5 minutes, 1000 events)
|
|
188
|
+
*/
|
|
189
|
+
getSnapshotFrequencyInfo(): {
|
|
190
|
+
sessionDuration: number;
|
|
191
|
+
currentInterval: number;
|
|
192
|
+
currentThreshold: number;
|
|
193
|
+
phase: string;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Test if the tracker can reach the ingestion server
|
|
197
|
+
*/
|
|
198
|
+
testConnection(): Promise<{
|
|
199
|
+
success: boolean;
|
|
200
|
+
error?: string;
|
|
201
|
+
}>;
|
|
202
|
+
/**
|
|
203
|
+
* Get connection status and recommendations
|
|
204
|
+
*/
|
|
205
|
+
getConnectionStatus(): {
|
|
206
|
+
blocked: boolean;
|
|
207
|
+
recommendations: string[];
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Check if the current user is a preexisting user
|
|
211
|
+
* Returns true if the user has an existing endUserId cookie from a previous session
|
|
212
|
+
*/
|
|
213
|
+
isPreexistingUser(): boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Get user information including whether they are preexisting
|
|
216
|
+
*/
|
|
217
|
+
getUserInfo(): {
|
|
218
|
+
endUserId: string | null;
|
|
219
|
+
sessionId: string;
|
|
220
|
+
isPreexistingUser: boolean;
|
|
221
|
+
initialized: boolean;
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
interface HumanBehaviorProviderProps {
|
|
226
|
+
apiKey?: string;
|
|
227
|
+
client?: HumanBehaviorTracker;
|
|
228
|
+
children: ReactNode;
|
|
229
|
+
options?: {
|
|
230
|
+
ingestionUrl?: string;
|
|
231
|
+
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
232
|
+
redactFields?: string[];
|
|
233
|
+
suppressConsoleErrors?: boolean;
|
|
234
|
+
recordCanvas?: boolean;
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
declare const HumanBehaviorProvider: ({ apiKey, client, children, options }: HumanBehaviorProviderProps) => React.JSX.Element;
|
|
238
|
+
declare const useHumanBehavior: () => HumanBehaviorTracker;
|
|
239
|
+
|
|
240
|
+
declare function createHumanBehaviorLoader(): ({ request }: LoaderFunctionArgs) => Promise<{
|
|
241
|
+
ENV: {
|
|
242
|
+
HUMANBEHAVIOR_API_KEY: string | undefined;
|
|
243
|
+
};
|
|
244
|
+
}>;
|
|
245
|
+
|
|
246
|
+
export { HumanBehaviorProvider, createHumanBehaviorLoader, useHumanBehavior };
|