humanbehavior-js 0.3.6 → 0.3.8
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/WIZARD_USAGE_GUIDE.md +381 -0
- package/dist/cjs/angular/index.cjs +53 -0
- package/dist/cjs/angular/index.cjs.map +1 -0
- package/dist/cjs/index.cjs +14230 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/install-wizard.cjs +1157 -0
- package/dist/cjs/install-wizard.cjs.map +1 -0
- package/dist/cjs/react/index.cjs +14387 -0
- package/dist/cjs/react/index.cjs.map +1 -0
- package/dist/cjs/remix/index.cjs +57 -0
- package/dist/cjs/remix/index.cjs.map +1 -0
- package/dist/cjs/svelte/index.cjs +13 -0
- package/dist/cjs/svelte/index.cjs.map +1 -0
- package/dist/cjs/vue/index.cjs +16 -0
- package/dist/cjs/vue/index.cjs.map +1 -0
- package/dist/cli/auto-install.js +1170 -0
- package/dist/cli/auto-install.js.map +1 -0
- package/dist/esm/angular/index.js +49 -0
- package/dist/esm/angular/index.js.map +1 -0
- package/dist/esm/index.js +12160 -3894
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/install-wizard.js +1134 -0
- package/dist/esm/install-wizard.js.map +1 -0
- package/dist/esm/react/index.js +14113 -70
- package/dist/esm/react/index.js.map +1 -1
- package/dist/esm/remix/index.js +47 -0
- package/dist/esm/remix/index.js.map +1 -0
- package/dist/esm/svelte/index.js +11 -0
- package/dist/esm/svelte/index.js.map +1 -0
- package/dist/esm/vue/index.js +14 -0
- package/dist/esm/vue/index.js.map +1 -0
- package/dist/index.min.js +1 -15
- package/dist/index.min.js.map +1 -1
- package/dist/types/angular/index.d.ts +240 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/install-wizard.d.ts +126 -0
- package/dist/types/react/index.d.ts +212 -3
- package/dist/types/remix/index.d.ts +10 -0
- package/dist/types/svelte/index.d.ts +216 -0
- package/dist/types/vue/index.d.ts +10 -0
- package/package.json +41 -9
- package/readme.md +72 -3
- package/rollup.config.js +263 -13
- package/src/angular/index.ts +54 -0
- package/src/api.ts +19 -2
- package/src/cli/auto-install.ts +225 -0
- package/src/index.ts +5 -2
- package/src/install-wizard.ts +1304 -0
- package/src/react/AutoInstallWizard.tsx +557 -0
- package/src/react/browser.ts +8 -0
- package/src/react/index.tsx +2 -4
- package/src/remix/index.ts +16 -0
- package/src/svelte/index.ts +8 -0
- package/src/tracker.ts +54 -24
- package/src/vue/index.ts +18 -0
- package/dist/cjs/index.js +0 -5967
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/react/index.js +0 -346
- package/dist/cjs/react/index.js.map +0 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
interface RedactionOptions {
|
|
2
|
+
redactedText?: string;
|
|
3
|
+
excludeSelectors?: string[];
|
|
4
|
+
userFields?: string[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
interface Window {
|
|
9
|
+
HumanBehaviorTracker: typeof HumanBehaviorTracker;
|
|
10
|
+
__humanBehaviorGlobalTracker?: HumanBehaviorTracker;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
declare class HumanBehaviorTracker {
|
|
14
|
+
private eventIngestionQueue;
|
|
15
|
+
private sessionId;
|
|
16
|
+
private userProperties;
|
|
17
|
+
private isProcessing;
|
|
18
|
+
private flushInterval;
|
|
19
|
+
private readonly FLUSH_INTERVAL_MS;
|
|
20
|
+
private api;
|
|
21
|
+
private endUserId;
|
|
22
|
+
private apiKey;
|
|
23
|
+
private initialized;
|
|
24
|
+
initializationPromise: Promise<void> | null;
|
|
25
|
+
private redactionManager;
|
|
26
|
+
private originalConsole;
|
|
27
|
+
private consoleTrackingEnabled;
|
|
28
|
+
navigationTrackingEnabled: boolean;
|
|
29
|
+
private currentUrl;
|
|
30
|
+
private previousUrl;
|
|
31
|
+
private originalPushState;
|
|
32
|
+
private originalReplaceState;
|
|
33
|
+
private navigationListeners;
|
|
34
|
+
private _connectionBlocked;
|
|
35
|
+
private recordInstance;
|
|
36
|
+
private sessionStartTime;
|
|
37
|
+
/**
|
|
38
|
+
* Initialize the HumanBehavior tracker
|
|
39
|
+
* This is the main entry point - call this once per page
|
|
40
|
+
*/
|
|
41
|
+
static init(apiKey: string, options?: {
|
|
42
|
+
ingestionUrl?: string;
|
|
43
|
+
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
44
|
+
redactFields?: string[];
|
|
45
|
+
enableAutomaticTracking?: boolean;
|
|
46
|
+
automaticTrackingOptions?: {
|
|
47
|
+
trackButtons?: boolean;
|
|
48
|
+
trackLinks?: boolean;
|
|
49
|
+
trackForms?: boolean;
|
|
50
|
+
includeText?: boolean;
|
|
51
|
+
includeClasses?: boolean;
|
|
52
|
+
};
|
|
53
|
+
}): HumanBehaviorTracker;
|
|
54
|
+
constructor(apiKey: string | undefined, ingestionUrl?: string);
|
|
55
|
+
private init;
|
|
56
|
+
private ensureInitialized;
|
|
57
|
+
/**
|
|
58
|
+
* Setup navigation event tracking for SPA navigation
|
|
59
|
+
*/
|
|
60
|
+
private setupNavigationTracking;
|
|
61
|
+
/**
|
|
62
|
+
* Track navigation events and send custom events
|
|
63
|
+
*/
|
|
64
|
+
trackNavigationEvent(type: string, fromUrl: string, toUrl: string): Promise<void>;
|
|
65
|
+
trackPageView(url?: string): Promise<void>;
|
|
66
|
+
customEvent(eventName: string, properties?: Record<string, any>): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Setup automatic tracking for buttons, links, and forms
|
|
69
|
+
*/
|
|
70
|
+
private setupAutomaticTracking;
|
|
71
|
+
/**
|
|
72
|
+
* Setup automatic button tracking
|
|
73
|
+
*/
|
|
74
|
+
private setupAutomaticButtonTracking;
|
|
75
|
+
/**
|
|
76
|
+
* Setup automatic link tracking
|
|
77
|
+
*/
|
|
78
|
+
private setupAutomaticLinkTracking;
|
|
79
|
+
/**
|
|
80
|
+
* Setup automatic form tracking
|
|
81
|
+
*/
|
|
82
|
+
private setupAutomaticFormTracking;
|
|
83
|
+
/**
|
|
84
|
+
* Cleanup navigation tracking
|
|
85
|
+
*/
|
|
86
|
+
private cleanupNavigationTracking;
|
|
87
|
+
static logToStorage(message: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Configure logging behavior for the SDK
|
|
90
|
+
* @param config Logger configuration options
|
|
91
|
+
*/
|
|
92
|
+
static configureLogging(config: {
|
|
93
|
+
level?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
94
|
+
enableConsole?: boolean;
|
|
95
|
+
enableStorage?: boolean;
|
|
96
|
+
}): void;
|
|
97
|
+
/**
|
|
98
|
+
* Enable console event tracking
|
|
99
|
+
*/
|
|
100
|
+
enableConsoleTracking(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Disable console event tracking
|
|
103
|
+
*/
|
|
104
|
+
disableConsoleTracking(): void;
|
|
105
|
+
private trackConsoleEvent;
|
|
106
|
+
private setupPageUnloadHandler;
|
|
107
|
+
viewLogs(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Add user identification information to the tracker
|
|
110
|
+
* If userId is not provided, will use userProperties.email as the userId (if present)
|
|
111
|
+
*/
|
|
112
|
+
identifyUser({ userProperties }: {
|
|
113
|
+
userProperties: Record<string, any>;
|
|
114
|
+
}): Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Get current user attributes
|
|
117
|
+
*/
|
|
118
|
+
getUserAttributes(): Record<string, any>;
|
|
119
|
+
start(): Promise<void>;
|
|
120
|
+
stop(): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Add an event to the ingestion queue
|
|
123
|
+
* Events are sent directly without processing to avoid corruption
|
|
124
|
+
*/
|
|
125
|
+
addEvent(event: any): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Flush events to the ingestion server
|
|
128
|
+
* Events are sent in chunks to handle large payloads efficiently
|
|
129
|
+
*/
|
|
130
|
+
private flush;
|
|
131
|
+
private setCookie;
|
|
132
|
+
getCookie(name: string): string | null;
|
|
133
|
+
/**
|
|
134
|
+
* Delete a cookie by setting its expiration date to the past
|
|
135
|
+
* @param name The name of the cookie to delete
|
|
136
|
+
*/
|
|
137
|
+
private deleteCookie;
|
|
138
|
+
/**
|
|
139
|
+
* Clear user data and reset session when user signs out of the site
|
|
140
|
+
* This should be called when a user logs out of your application to prevent
|
|
141
|
+
* data contamination between different users
|
|
142
|
+
*/
|
|
143
|
+
logout(): void;
|
|
144
|
+
/**
|
|
145
|
+
* Start redaction functionality for sensitive input fields
|
|
146
|
+
* @param options Optional configuration for redaction behavior
|
|
147
|
+
*/
|
|
148
|
+
redact(options?: RedactionOptions): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Set specific fields to be redacted during session recording
|
|
151
|
+
* Uses rrweb's built-in masking instead of custom redaction processing
|
|
152
|
+
* @param fields Array of CSS selectors for fields to redact (e.g., ['input[type="password"]', '#email-field'])
|
|
153
|
+
*/
|
|
154
|
+
setRedactedFields(fields: string[]): void;
|
|
155
|
+
private restartWithNewRedaction;
|
|
156
|
+
/**
|
|
157
|
+
* Check if redaction is currently active
|
|
158
|
+
*/
|
|
159
|
+
isRedactionActive(): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Get the currently selected fields for redaction
|
|
162
|
+
*/
|
|
163
|
+
getRedactedFields(): string[];
|
|
164
|
+
/**
|
|
165
|
+
* Get the current session ID
|
|
166
|
+
*/
|
|
167
|
+
getSessionId(): string;
|
|
168
|
+
/**
|
|
169
|
+
* Get the current URL being tracked
|
|
170
|
+
*/
|
|
171
|
+
getCurrentUrl(): string;
|
|
172
|
+
/**
|
|
173
|
+
* Get current snapshot frequency info
|
|
174
|
+
* Uses configured values (5 minutes, 1000 events)
|
|
175
|
+
*/
|
|
176
|
+
getSnapshotFrequencyInfo(): {
|
|
177
|
+
sessionDuration: number;
|
|
178
|
+
currentInterval: number;
|
|
179
|
+
currentThreshold: number;
|
|
180
|
+
phase: string;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Test if the tracker can reach the ingestion server
|
|
184
|
+
*/
|
|
185
|
+
testConnection(): Promise<{
|
|
186
|
+
success: boolean;
|
|
187
|
+
error?: string;
|
|
188
|
+
}>;
|
|
189
|
+
/**
|
|
190
|
+
* Get connection status and recommendations
|
|
191
|
+
*/
|
|
192
|
+
getConnectionStatus(): {
|
|
193
|
+
blocked: boolean;
|
|
194
|
+
recommendations: string[];
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Check if the current user is a preexisting user
|
|
198
|
+
* Returns true if the user has an existing endUserId cookie from a previous session
|
|
199
|
+
*/
|
|
200
|
+
isPreexistingUser(): boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Get user information including whether they are preexisting
|
|
203
|
+
*/
|
|
204
|
+
getUserInfo(): {
|
|
205
|
+
endUserId: string | null;
|
|
206
|
+
sessionId: string;
|
|
207
|
+
isPreexistingUser: boolean;
|
|
208
|
+
initialized: boolean;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
declare class HumanBehaviorModule {
|
|
213
|
+
static forRoot(config: {
|
|
214
|
+
apiKey: string;
|
|
215
|
+
}): {
|
|
216
|
+
ngModule: typeof HumanBehaviorModule;
|
|
217
|
+
providers: ({
|
|
218
|
+
provide: string;
|
|
219
|
+
useValue: string;
|
|
220
|
+
useFactory?: undefined;
|
|
221
|
+
deps?: undefined;
|
|
222
|
+
} | {
|
|
223
|
+
provide: typeof HumanBehaviorTracker;
|
|
224
|
+
useFactory: (apiKey: string) => HumanBehaviorTracker;
|
|
225
|
+
deps: string[];
|
|
226
|
+
useValue?: undefined;
|
|
227
|
+
})[];
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
declare class HumanBehaviorService {
|
|
231
|
+
private tracker;
|
|
232
|
+
constructor(apiKey: string);
|
|
233
|
+
identifyUser(userProperties: Record<string, any>): Promise<string>;
|
|
234
|
+
getSessionId(): string;
|
|
235
|
+
setRedactedFields(fields: string[]): void;
|
|
236
|
+
getRedactedFields(): string[];
|
|
237
|
+
}
|
|
238
|
+
declare function initializeHumanBehavior(apiKey: string): HumanBehaviorTracker;
|
|
239
|
+
|
|
240
|
+
export { HumanBehaviorModule, HumanBehaviorService, initializeHumanBehavior };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -261,7 +261,7 @@ declare class HumanBehaviorTracker {
|
|
|
261
261
|
getCurrentUrl(): string;
|
|
262
262
|
/**
|
|
263
263
|
* Get current snapshot frequency info
|
|
264
|
-
* Uses configured values (5 minutes, 1000 events)
|
|
264
|
+
* Uses configured values (5 minutes, 1000 events)
|
|
265
265
|
*/
|
|
266
266
|
getSnapshotFrequencyInfo(): {
|
|
267
267
|
sessionDuration: number;
|
|
@@ -359,5 +359,5 @@ declare const logWarn: (message: string, ...args: any[]) => void;
|
|
|
359
359
|
declare const logInfo: (message: string, ...args: any[]) => void;
|
|
360
360
|
declare const logDebug: (message: string, ...args: any[]) => void;
|
|
361
361
|
|
|
362
|
-
export { HumanBehaviorAPI, HumanBehaviorTracker, LogLevel, MAX_CHUNK_SIZE_BYTES, RedactionManager,
|
|
362
|
+
export { HumanBehaviorAPI, HumanBehaviorTracker, LogLevel, MAX_CHUNK_SIZE_BYTES, RedactionManager, isChunkSizeExceeded, logDebug, logError, logInfo, logWarn, logger, redactionManager, splitLargeEvent, validateSingleEventSize };
|
|
363
363
|
export type { LoggerConfig, RedactionOptions };
|
|
@@ -0,0 +1,126 @@
|
|
|
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' | 'node';
|
|
10
|
+
bundler?: 'vite' | 'webpack' | 'esbuild' | 'rollup';
|
|
11
|
+
packageManager?: 'npm' | 'yarn' | 'pnpm';
|
|
12
|
+
hasTypeScript?: boolean;
|
|
13
|
+
hasRouter?: boolean;
|
|
14
|
+
projectRoot?: string;
|
|
15
|
+
}
|
|
16
|
+
interface CodeModification {
|
|
17
|
+
filePath: string;
|
|
18
|
+
action: 'create' | 'modify' | 'append';
|
|
19
|
+
content: string;
|
|
20
|
+
description: string;
|
|
21
|
+
}
|
|
22
|
+
interface InstallationResult {
|
|
23
|
+
success: boolean;
|
|
24
|
+
framework: FrameworkInfo;
|
|
25
|
+
modifications: CodeModification[];
|
|
26
|
+
errors: string[];
|
|
27
|
+
nextSteps: string[];
|
|
28
|
+
}
|
|
29
|
+
declare class AutoInstallationWizard {
|
|
30
|
+
private apiKey;
|
|
31
|
+
private projectRoot;
|
|
32
|
+
private framework;
|
|
33
|
+
constructor(apiKey: string, projectRoot?: string);
|
|
34
|
+
/**
|
|
35
|
+
* Main installation method - detects framework and auto-installs
|
|
36
|
+
*/
|
|
37
|
+
install(): Promise<InstallationResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Detect the current framework and project setup
|
|
40
|
+
*/
|
|
41
|
+
private detectFramework;
|
|
42
|
+
/**
|
|
43
|
+
* Install the SDK package
|
|
44
|
+
*/
|
|
45
|
+
private installPackage;
|
|
46
|
+
/**
|
|
47
|
+
* Generate code modifications based on framework
|
|
48
|
+
*/
|
|
49
|
+
private generateModifications;
|
|
50
|
+
/**
|
|
51
|
+
* Generate React-specific modifications
|
|
52
|
+
*/
|
|
53
|
+
private generateReactModifications;
|
|
54
|
+
/**
|
|
55
|
+
* Generate Next.js-specific modifications
|
|
56
|
+
*/
|
|
57
|
+
private generateNextJSModifications;
|
|
58
|
+
/**
|
|
59
|
+
* Generate Nuxt-specific modifications
|
|
60
|
+
*/
|
|
61
|
+
private generateNuxtModifications;
|
|
62
|
+
/**
|
|
63
|
+
* Generate Remix-specific modifications
|
|
64
|
+
*/
|
|
65
|
+
private generateRemixModifications;
|
|
66
|
+
/**
|
|
67
|
+
* Generate Vue-specific modifications
|
|
68
|
+
*/
|
|
69
|
+
private generateVueModifications;
|
|
70
|
+
/**
|
|
71
|
+
* Generate Angular-specific modifications
|
|
72
|
+
*/
|
|
73
|
+
private generateAngularModifications;
|
|
74
|
+
/**
|
|
75
|
+
* Generate Svelte-specific modifications
|
|
76
|
+
*/
|
|
77
|
+
private generateSvelteModifications;
|
|
78
|
+
/**
|
|
79
|
+
* Generate vanilla JS/TS modifications
|
|
80
|
+
*/
|
|
81
|
+
private generateVanillaModifications;
|
|
82
|
+
/**
|
|
83
|
+
* Apply modifications to the codebase
|
|
84
|
+
*/
|
|
85
|
+
private applyModifications;
|
|
86
|
+
/**
|
|
87
|
+
* Generate next steps for the user
|
|
88
|
+
*/
|
|
89
|
+
private generateNextSteps;
|
|
90
|
+
private findReactAppFile;
|
|
91
|
+
private findVueMainFile;
|
|
92
|
+
private findSvelteMainFile;
|
|
93
|
+
private findHTMLFile;
|
|
94
|
+
private injectReactProvider;
|
|
95
|
+
private injectNextJSAppRouter;
|
|
96
|
+
private injectNextJSPagesRouter;
|
|
97
|
+
private injectRemixProvider;
|
|
98
|
+
private injectVuePlugin;
|
|
99
|
+
private injectAngularModule;
|
|
100
|
+
private injectAngularStandaloneInit;
|
|
101
|
+
private injectSvelteStore;
|
|
102
|
+
private injectSvelteKitLayout;
|
|
103
|
+
private injectVanillaScript;
|
|
104
|
+
private injectNuxtConfig;
|
|
105
|
+
/**
|
|
106
|
+
* Helper method to find the best environment file for a framework
|
|
107
|
+
*/
|
|
108
|
+
private findBestEnvFile;
|
|
109
|
+
/**
|
|
110
|
+
* Helper method to create or append to environment files
|
|
111
|
+
*/
|
|
112
|
+
private createEnvironmentModification;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Browser-based auto-installation wizard
|
|
116
|
+
*/
|
|
117
|
+
declare class BrowserAutoInstallationWizard {
|
|
118
|
+
private apiKey;
|
|
119
|
+
constructor(apiKey: string);
|
|
120
|
+
install(): Promise<InstallationResult>;
|
|
121
|
+
private detectFramework;
|
|
122
|
+
private generateBrowserModifications;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { AutoInstallationWizard, BrowserAutoInstallationWizard };
|
|
126
|
+
export type { CodeModification, FrameworkInfo, InstallationResult };
|
|
@@ -1,6 +1,215 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
/**
|
|
40
|
+
* Initialize the HumanBehavior tracker
|
|
41
|
+
* This is the main entry point - call this once per page
|
|
42
|
+
*/
|
|
43
|
+
static init(apiKey: string, options?: {
|
|
44
|
+
ingestionUrl?: string;
|
|
45
|
+
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
46
|
+
redactFields?: string[];
|
|
47
|
+
enableAutomaticTracking?: boolean;
|
|
48
|
+
automaticTrackingOptions?: {
|
|
49
|
+
trackButtons?: boolean;
|
|
50
|
+
trackLinks?: boolean;
|
|
51
|
+
trackForms?: boolean;
|
|
52
|
+
includeText?: boolean;
|
|
53
|
+
includeClasses?: boolean;
|
|
54
|
+
};
|
|
55
|
+
}): HumanBehaviorTracker;
|
|
56
|
+
constructor(apiKey: string | undefined, ingestionUrl?: string);
|
|
57
|
+
private init;
|
|
58
|
+
private ensureInitialized;
|
|
59
|
+
/**
|
|
60
|
+
* Setup navigation event tracking for SPA navigation
|
|
61
|
+
*/
|
|
62
|
+
private setupNavigationTracking;
|
|
63
|
+
/**
|
|
64
|
+
* Track navigation events and send custom events
|
|
65
|
+
*/
|
|
66
|
+
trackNavigationEvent(type: string, fromUrl: string, toUrl: string): Promise<void>;
|
|
67
|
+
trackPageView(url?: string): Promise<void>;
|
|
68
|
+
customEvent(eventName: string, properties?: Record<string, any>): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Setup automatic tracking for buttons, links, and forms
|
|
71
|
+
*/
|
|
72
|
+
private setupAutomaticTracking;
|
|
73
|
+
/**
|
|
74
|
+
* Setup automatic button tracking
|
|
75
|
+
*/
|
|
76
|
+
private setupAutomaticButtonTracking;
|
|
77
|
+
/**
|
|
78
|
+
* Setup automatic link tracking
|
|
79
|
+
*/
|
|
80
|
+
private setupAutomaticLinkTracking;
|
|
81
|
+
/**
|
|
82
|
+
* Setup automatic form tracking
|
|
83
|
+
*/
|
|
84
|
+
private setupAutomaticFormTracking;
|
|
85
|
+
/**
|
|
86
|
+
* Cleanup navigation tracking
|
|
87
|
+
*/
|
|
88
|
+
private cleanupNavigationTracking;
|
|
89
|
+
static logToStorage(message: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Configure logging behavior for the SDK
|
|
92
|
+
* @param config Logger configuration options
|
|
93
|
+
*/
|
|
94
|
+
static configureLogging(config: {
|
|
95
|
+
level?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
96
|
+
enableConsole?: boolean;
|
|
97
|
+
enableStorage?: boolean;
|
|
98
|
+
}): void;
|
|
99
|
+
/**
|
|
100
|
+
* Enable console event tracking
|
|
101
|
+
*/
|
|
102
|
+
enableConsoleTracking(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Disable console event tracking
|
|
105
|
+
*/
|
|
106
|
+
disableConsoleTracking(): void;
|
|
107
|
+
private trackConsoleEvent;
|
|
108
|
+
private setupPageUnloadHandler;
|
|
109
|
+
viewLogs(): void;
|
|
110
|
+
/**
|
|
111
|
+
* Add user identification information to the tracker
|
|
112
|
+
* If userId is not provided, will use userProperties.email as the userId (if present)
|
|
113
|
+
*/
|
|
114
|
+
identifyUser({ userProperties }: {
|
|
115
|
+
userProperties: Record<string, any>;
|
|
116
|
+
}): Promise<string>;
|
|
117
|
+
/**
|
|
118
|
+
* Get current user attributes
|
|
119
|
+
*/
|
|
120
|
+
getUserAttributes(): Record<string, any>;
|
|
121
|
+
start(): Promise<void>;
|
|
122
|
+
stop(): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Add an event to the ingestion queue
|
|
125
|
+
* Events are sent directly without processing to avoid corruption
|
|
126
|
+
*/
|
|
127
|
+
addEvent(event: any): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Flush events to the ingestion server
|
|
130
|
+
* Events are sent in chunks to handle large payloads efficiently
|
|
131
|
+
*/
|
|
132
|
+
private flush;
|
|
133
|
+
private setCookie;
|
|
134
|
+
getCookie(name: string): string | null;
|
|
135
|
+
/**
|
|
136
|
+
* Delete a cookie by setting its expiration date to the past
|
|
137
|
+
* @param name The name of the cookie to delete
|
|
138
|
+
*/
|
|
139
|
+
private deleteCookie;
|
|
140
|
+
/**
|
|
141
|
+
* Clear user data and reset session when user signs out of the site
|
|
142
|
+
* This should be called when a user logs out of your application to prevent
|
|
143
|
+
* data contamination between different users
|
|
144
|
+
*/
|
|
145
|
+
logout(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Start redaction functionality for sensitive input fields
|
|
148
|
+
* @param options Optional configuration for redaction behavior
|
|
149
|
+
*/
|
|
150
|
+
redact(options?: RedactionOptions): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Set specific fields to be redacted during session recording
|
|
153
|
+
* Uses rrweb's built-in masking instead of custom redaction processing
|
|
154
|
+
* @param fields Array of CSS selectors for fields to redact (e.g., ['input[type="password"]', '#email-field'])
|
|
155
|
+
*/
|
|
156
|
+
setRedactedFields(fields: string[]): void;
|
|
157
|
+
private restartWithNewRedaction;
|
|
158
|
+
/**
|
|
159
|
+
* Check if redaction is currently active
|
|
160
|
+
*/
|
|
161
|
+
isRedactionActive(): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Get the currently selected fields for redaction
|
|
164
|
+
*/
|
|
165
|
+
getRedactedFields(): string[];
|
|
166
|
+
/**
|
|
167
|
+
* Get the current session ID
|
|
168
|
+
*/
|
|
169
|
+
getSessionId(): string;
|
|
170
|
+
/**
|
|
171
|
+
* Get the current URL being tracked
|
|
172
|
+
*/
|
|
173
|
+
getCurrentUrl(): string;
|
|
174
|
+
/**
|
|
175
|
+
* Get current snapshot frequency info
|
|
176
|
+
* Uses configured values (5 minutes, 1000 events)
|
|
177
|
+
*/
|
|
178
|
+
getSnapshotFrequencyInfo(): {
|
|
179
|
+
sessionDuration: number;
|
|
180
|
+
currentInterval: number;
|
|
181
|
+
currentThreshold: number;
|
|
182
|
+
phase: string;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Test if the tracker can reach the ingestion server
|
|
186
|
+
*/
|
|
187
|
+
testConnection(): Promise<{
|
|
188
|
+
success: boolean;
|
|
189
|
+
error?: string;
|
|
190
|
+
}>;
|
|
191
|
+
/**
|
|
192
|
+
* Get connection status and recommendations
|
|
193
|
+
*/
|
|
194
|
+
getConnectionStatus(): {
|
|
195
|
+
blocked: boolean;
|
|
196
|
+
recommendations: string[];
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Check if the current user is a preexisting user
|
|
200
|
+
* Returns true if the user has an existing endUserId cookie from a previous session
|
|
201
|
+
*/
|
|
202
|
+
isPreexistingUser(): boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Get user information including whether they are preexisting
|
|
205
|
+
*/
|
|
206
|
+
getUserInfo(): {
|
|
207
|
+
endUserId: string | null;
|
|
208
|
+
sessionId: string;
|
|
209
|
+
isPreexistingUser: boolean;
|
|
210
|
+
initialized: boolean;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
4
213
|
|
|
5
214
|
interface HumanBehaviorProviderProps {
|
|
6
215
|
apiKey?: string;
|
|
@@ -31,4 +240,4 @@ declare const useUserTracking: () => {
|
|
|
31
240
|
}>;
|
|
32
241
|
};
|
|
33
242
|
|
|
34
|
-
export { HumanBehaviorProvider, useHumanBehavior, useRedaction, useUserTracking };
|
|
243
|
+
export { HumanBehaviorProvider, HumanBehaviorTracker, useHumanBehavior, useRedaction, useUserTracking };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LoaderFunctionArgs } from '@remix-run/node';
|
|
2
|
+
export { HumanBehaviorProvider, useHumanBehavior } from '../react';
|
|
3
|
+
|
|
4
|
+
declare function createHumanBehaviorLoader(): ({ request }: LoaderFunctionArgs) => Promise<{
|
|
5
|
+
ENV: {
|
|
6
|
+
HUMANBEHAVIOR_API_KEY: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
export { createHumanBehaviorLoader };
|