humanbehavior-js 0.4.27 → 0.5.0

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.
Files changed (140) hide show
  1. package/README.md +151 -0
  2. package/package.json +114 -71
  3. package/packages/angular/dist/index.d.ts +46 -0
  4. package/packages/angular/dist/index.d.ts.map +1 -0
  5. package/packages/angular/dist/index.js +2 -0
  6. package/packages/angular/dist/index.js.map +1 -0
  7. package/packages/angular/dist/index.mjs +2 -0
  8. package/packages/angular/dist/index.mjs.map +1 -0
  9. package/packages/browser/dist/index.d.ts +5 -0
  10. package/packages/browser/dist/index.d.ts.map +1 -0
  11. package/packages/browser/dist/index.iife.js +12095 -0
  12. package/packages/browser/dist/index.iife.js.map +1 -0
  13. package/packages/browser/dist/index.js +2 -0
  14. package/packages/browser/dist/index.js.map +1 -0
  15. package/packages/browser/dist/index.min.js +2 -0
  16. package/packages/browser/dist/index.min.js.map +1 -0
  17. package/packages/browser/dist/index.mjs +2 -0
  18. package/packages/browser/dist/index.mjs.map +1 -0
  19. package/packages/react/dist/browser.d.ts +2 -0
  20. package/packages/react/dist/browser.d.ts.map +1 -0
  21. package/packages/react/dist/index.d.ts +48 -0
  22. package/packages/react/dist/index.d.ts.map +1 -0
  23. package/packages/react/dist/index.js +2 -0
  24. package/packages/react/dist/index.js.map +1 -0
  25. package/packages/react/dist/index.mjs +2 -0
  26. package/packages/react/dist/index.mjs.map +1 -0
  27. package/packages/remix/dist/index.d.ts +8 -0
  28. package/packages/remix/dist/index.d.ts.map +1 -0
  29. package/packages/remix/dist/index.js +2 -0
  30. package/packages/remix/dist/index.js.map +1 -0
  31. package/packages/remix/dist/index.mjs +2 -0
  32. package/packages/remix/dist/index.mjs.map +1 -0
  33. package/packages/svelte/dist/index.d.ts +11 -0
  34. package/packages/svelte/dist/index.d.ts.map +1 -0
  35. package/packages/svelte/dist/index.js +2 -0
  36. package/packages/svelte/dist/index.js.map +1 -0
  37. package/packages/svelte/dist/index.mjs +2 -0
  38. package/packages/svelte/dist/index.mjs.map +1 -0
  39. package/{dist/types/vue → packages/vue/dist}/index.d.ts +4 -5
  40. package/packages/vue/dist/index.d.ts.map +1 -0
  41. package/packages/vue/dist/index.js +2 -0
  42. package/packages/vue/dist/index.js.map +1 -0
  43. package/packages/vue/dist/index.mjs +2 -0
  44. package/packages/vue/dist/index.mjs.map +1 -0
  45. package/packages/wizard/dist/ai/ai-install-wizard.d.ts +145 -0
  46. package/packages/wizard/dist/ai/ai-install-wizard.d.ts.map +1 -0
  47. package/packages/wizard/dist/ai/manual-framework-wizard.d.ts +52 -0
  48. package/packages/wizard/dist/ai/manual-framework-wizard.d.ts.map +1 -0
  49. package/packages/wizard/dist/cli/ai-auto-install.d.ts +27 -0
  50. package/packages/wizard/dist/cli/ai-auto-install.d.ts.map +1 -0
  51. package/{dist → packages/wizard/dist}/cli/ai-auto-install.js +821 -905
  52. package/packages/wizard/dist/cli/ai-auto-install.js.map +1 -0
  53. package/packages/wizard/dist/cli/auto-install.d.ts +26 -0
  54. package/packages/wizard/dist/cli/auto-install.d.ts.map +1 -0
  55. package/{dist → packages/wizard/dist}/cli/auto-install.js +821 -905
  56. package/packages/wizard/dist/cli/auto-install.js.map +1 -0
  57. package/{dist/types → packages/wizard/dist/core}/install-wizard.d.ts +6 -8
  58. package/packages/wizard/dist/core/install-wizard.d.ts.map +1 -0
  59. package/packages/wizard/dist/index.d.ts +18 -0
  60. package/packages/wizard/dist/index.d.ts.map +1 -0
  61. package/packages/wizard/dist/index.js +2 -0
  62. package/packages/wizard/dist/index.js.map +1 -0
  63. package/packages/wizard/dist/index.mjs +2 -0
  64. package/packages/wizard/dist/index.mjs.map +1 -0
  65. package/packages/wizard/dist/services/centralized-ai-service.d.ts +159 -0
  66. package/packages/wizard/dist/services/centralized-ai-service.d.ts.map +1 -0
  67. package/packages/wizard/dist/services/remote-ai-service.d.ts +58 -0
  68. package/packages/wizard/dist/services/remote-ai-service.d.ts.map +1 -0
  69. package/WIZARD_USAGE_GUIDE.md +0 -381
  70. package/dist/cjs/angular/index.cjs +0 -14979
  71. package/dist/cjs/angular/index.cjs.map +0 -1
  72. package/dist/cjs/index.cjs +0 -14964
  73. package/dist/cjs/index.cjs.map +0 -1
  74. package/dist/cjs/install-wizard.cjs +0 -1576
  75. package/dist/cjs/install-wizard.cjs.map +0 -1
  76. package/dist/cjs/react/index.cjs +0 -15103
  77. package/dist/cjs/react/index.cjs.map +0 -1
  78. package/dist/cjs/remix/index.cjs +0 -15077
  79. package/dist/cjs/remix/index.cjs.map +0 -1
  80. package/dist/cjs/svelte/index.cjs +0 -14933
  81. package/dist/cjs/svelte/index.cjs.map +0 -1
  82. package/dist/cjs/vue/index.cjs +0 -14942
  83. package/dist/cjs/vue/index.cjs.map +0 -1
  84. package/dist/cjs/wizard/index.cjs +0 -3490
  85. package/dist/cjs/wizard/index.cjs.map +0 -1
  86. package/dist/cli/ai-auto-install.js.map +0 -1
  87. package/dist/cli/auto-install.js.map +0 -1
  88. package/dist/esm/angular/index.js +0 -14975
  89. package/dist/esm/angular/index.js.map +0 -1
  90. package/dist/esm/index.js +0 -14941
  91. package/dist/esm/index.js.map +0 -1
  92. package/dist/esm/install-wizard.js +0 -1553
  93. package/dist/esm/install-wizard.js.map +0 -1
  94. package/dist/esm/react/index.js +0 -15097
  95. package/dist/esm/react/index.js.map +0 -1
  96. package/dist/esm/remix/index.js +0 -15073
  97. package/dist/esm/remix/index.js.map +0 -1
  98. package/dist/esm/svelte/index.js +0 -14931
  99. package/dist/esm/svelte/index.js.map +0 -1
  100. package/dist/esm/vue/index.js +0 -14940
  101. package/dist/esm/vue/index.js.map +0 -1
  102. package/dist/esm/wizard/index.js +0 -3459
  103. package/dist/esm/wizard/index.js.map +0 -1
  104. package/dist/index.min.js +0 -2
  105. package/dist/index.min.js.map +0 -1
  106. package/dist/types/angular/index.d.ts +0 -357
  107. package/dist/types/index.d.ts +0 -644
  108. package/dist/types/react/index.d.ts +0 -345
  109. package/dist/types/remix/index.d.ts +0 -336
  110. package/dist/types/svelte/index.d.ts +0 -322
  111. package/dist/types/wizard/index.d.ts +0 -523
  112. package/readme.md +0 -335
  113. package/rollup.config.js +0 -422
  114. package/simple-spa.html +0 -1000
  115. package/src/angular/index.ts +0 -79
  116. package/src/api.ts +0 -416
  117. package/src/index.ts +0 -35
  118. package/src/react/AutoInstallWizard.tsx +0 -557
  119. package/src/react/browser.ts +0 -8
  120. package/src/react/index.tsx +0 -308
  121. package/src/redact.ts +0 -327
  122. package/src/remix/index.ts +0 -16
  123. package/src/svelte/index.ts +0 -14
  124. package/src/tracker.ts +0 -1587
  125. package/src/types/clack.d.ts +0 -31
  126. package/src/utils/ip-detector.ts +0 -158
  127. package/src/utils/logger.ts +0 -144
  128. package/src/utils/property-detector.ts +0 -345
  129. package/src/utils/property-manager.ts +0 -274
  130. package/src/vue/index.ts +0 -29
  131. package/src/wizard/README.md +0 -114
  132. package/src/wizard/ai/ai-install-wizard.ts +0 -897
  133. package/src/wizard/ai/manual-framework-wizard.ts +0 -238
  134. package/src/wizard/cli/ai-auto-install.ts +0 -241
  135. package/src/wizard/cli/auto-install.ts +0 -224
  136. package/src/wizard/core/install-wizard.ts +0 -1794
  137. package/src/wizard/index.ts +0 -23
  138. package/src/wizard/services/centralized-ai-service.ts +0 -668
  139. package/src/wizard/services/remote-ai-service.ts +0 -240
  140. package/tsconfig.json +0 -24
package/readme.md DELETED
@@ -1,335 +0,0 @@
1
- # HumanBehavior SDK
2
-
3
- A simplified session recording and analytics SDK that maintains session continuity across page navigations.
4
-
5
- 📖 **[Full Documentation](https://documentation.humanbehavior.co)** - Complete API reference, examples, and integration guides
6
-
7
- ## Quick Start
8
-
9
- ### Auto-Installation (Recommended)
10
-
11
- The easiest way to get started is using our auto-installation wizard:
12
-
13
- ```bash
14
- # One command installation
15
- npx humanbehavior-js auto-install YOUR_API_KEY
16
- ```
17
-
18
- This will automatically:
19
- - 🔍 Detect your project's framework
20
- - 📦 Install the humanbehavior-js package
21
- - ✏️ Modify your codebase to integrate the SDK
22
- - 🔧 Create environment files with your API key
23
- - 🚀 Make your app ready to track user behavior
24
-
25
- ### Single Page Application (Manual Setup)
26
-
27
- For the best session continuity experience, use the SPA approach:
28
-
29
- ```html
30
- <!DOCTYPE html>
31
- <html>
32
- <head>
33
- <script src="dist/index.min.js"></script>
34
- </head>
35
- <body>
36
- <script>
37
- // Initialize once - session persists across all navigation
38
- const tracker = HumanBehaviorTracker.init('your-api-key', {
39
- logLevel: 'warn', // Reduce console noise
40
- redactFields: ['password', 'credit_card'],
41
- suppressConsoleErrors: true, // Suppress common rrweb errors (default)
42
- recordCanvas: false // Enable canvas recording with protection (default: false)
43
- });
44
-
45
- // Your SPA navigation logic here
46
- function navigateToPage(page) {
47
- // Update content without page reload
48
- loadPageContent(page);
49
-
50
- // Track navigation
51
- tracker.trackNavigationEvent('spa_navigation', currentPage, page);
52
- }
53
- </script>
54
- </body>
55
- </html>
56
- ```
57
-
58
- ### Traditional Multi-Page Setup
59
-
60
- For traditional HTML pages, the tracker will automatically restore sessions:
61
-
62
- ```html
63
- <!-- index.html -->
64
- <script src="dist/index.min.js"></script>
65
- <script>
66
- const tracker = HumanBehaviorTracker.init('your-api-key');
67
- </script>
68
-
69
- <!-- about.html -->
70
- <script src="dist/index.min.js"></script>
71
- <script>
72
- const tracker = HumanBehaviorTracker.init('your-api-key'); // Reuses existing session
73
- </script>
74
- ```
75
-
76
- ## API Reference
77
-
78
- ### Initialization
79
-
80
- ```javascript
81
- // Main initialization method
82
- const tracker = HumanBehaviorTracker.init(apiKey, options);
83
- ```
84
-
85
- **Options:**
86
- - `ingestionUrl`: Custom ingestion server URL
87
- - `logLevel`: 'none' | 'error' | 'warn' | 'info' | 'debug'
88
- - `redactFields`: Array of CSS selectors to unredact (DEPRECATED: Use redactionStrategy instead)
89
- - `redactionStrategy`: Flexible redaction configuration
90
- - `mode`: 'privacy-first' | 'visibility-first' (default: 'privacy-first')
91
- - `unredactFields`: Array of CSS selectors to make visible (when mode: 'privacy-first')
92
- - `redactFields`: Array of CSS selectors to hide (when mode: 'visibility-first')
93
- - `suppressConsoleErrors`: Boolean to suppress common rrweb errors (default: true)
94
- - `recordCanvas`: Boolean to enable canvas recording with PostHog-style protection (default: false)
95
-
96
- ### Session Management
97
-
98
- ```javascript
99
- // Get current session ID
100
- const sessionId = tracker.getSessionId();
101
-
102
- // Get current URL
103
- const currentUrl = tracker.getCurrentUrl();
104
-
105
- // Test connection to ingestion server
106
- const result = await tracker.testConnection();
107
- ```
108
-
109
- ### Event Tracking
110
-
111
- ```javascript
112
- // Track custom events
113
- await tracker.customEvent('button_click', { button: 'submit' });
114
-
115
- // Track page views
116
- await tracker.trackPageView();
117
-
118
- // Track navigation (for SPAs)
119
- await tracker.trackNavigationEvent('pushState', '/home', '/about');
120
- ```
121
-
122
- ### Data Redaction
123
-
124
- The SDK supports flexible redaction strategies to protect sensitive data:
125
-
126
- #### Privacy-First Mode (Default)
127
- Everything is redacted by default. Specify fields to unredact:
128
-
129
- ```javascript
130
- // Privacy-first: everything redacted, unredact specific fields
131
- const tracker = HumanBehaviorTracker.init('your-api-key', {
132
- redactionStrategy: {
133
- mode: 'privacy-first',
134
- unredactFields: ['#username', '#comment', '.public-field']
135
- }
136
- });
137
- ```
138
-
139
- #### Visibility-First Mode
140
- Everything is visible by default. Specify fields to redact:
141
-
142
- ```javascript
143
- // Visibility-first: everything visible, redact specific fields
144
- const tracker = HumanBehaviorTracker.init('your-api-key', {
145
- redactionStrategy: {
146
- mode: 'visibility-first',
147
- redactFields: ['#password', '#credit-card', '.sensitive-data']
148
- }
149
- });
150
- ```
151
-
152
- #### Legacy Support
153
- The old `redactFields` option still works (privacy-first mode):
154
-
155
- ```javascript
156
- // Legacy: same as privacy-first mode
157
- const tracker = HumanBehaviorTracker.init('your-api-key', {
158
- redactFields: ['#username', '#email'] // These fields will be unredacted
159
- });
160
- ```
161
-
162
- #### Dynamic Redaction
163
- Change redaction settings at runtime:
164
-
165
- ```javascript
166
- // Privacy-first: add fields to unredact
167
- tracker.setUnredactedFields(['#new-field', '.another-field']);
168
-
169
- // Visibility-first: add fields to redact
170
- tracker.setRedactedFields(['#sensitive-field', '.private-data']);
171
-
172
- // Clear all settings
173
- tracker.clearUnredactedFields(); // Privacy-first
174
- tracker.clearRedactedFields(); // Visibility-first
175
- ```
176
-
177
- #### Security Features
178
- - **Password fields always protected** (cannot be unredacted in any mode)
179
- - **CSS selector validation** (prevents invalid selectors)
180
- - **Runtime safety checks** (handles DOM errors gracefully)
181
-
182
- ### Debugging
183
-
184
- ```javascript
185
- // View logs
186
- tracker.viewLogs();
187
-
188
- // Get connection status
189
- const status = tracker.getConnectionStatus();
190
- ```
191
-
192
- ### Error Suppression
193
-
194
- The SDK automatically suppresses common rrweb errors for a clean console:
195
-
196
- ```javascript
197
- // Enable error suppression (default)
198
- const tracker = HumanBehaviorTracker.init('your-api-key', {
199
- suppressConsoleErrors: true // Suppresses canvas security errors, CORS issues, etc.
200
- });
201
-
202
- // Disable error suppression for debugging
203
- const tracker = HumanBehaviorTracker.init('your-api-key', {
204
- suppressConsoleErrors: false // Show all errors for debugging
205
- });
206
- ```
207
-
208
- **Suppressed Errors:**
209
- - Canvas security errors (`SecurityError: Failed to execute 'toDataURL'`)
210
- - Cross-origin resource errors
211
- - CORS policy violations
212
- - Ad blocker interference warnings
213
-
214
- ### Canvas Recording
215
-
216
- The SDK supports canvas recording with PostHog-style protection against overwhelming events:
217
-
218
- ```javascript
219
- // Enable canvas recording with protection
220
- const tracker = HumanBehaviorTracker.init('your-api-key', {
221
- recordCanvas: true // Enables canvas recording with 4 FPS throttle and 40% quality
222
- });
223
- ```
224
-
225
- **Protection Features:**
226
- - **4 FPS Throttling**: Prevents canvas overwhelm (vs 60 FPS default)
227
- - **40% Quality**: WebP format with compression
228
- - **Opt-in Only**: Disabled by default for safety
229
- - **Smart Sampling**: Only captures when canvas changes
230
-
231
- ## Session Continuity
232
-
233
- The SDK automatically handles session continuity:
234
-
235
- 1. **Session Restoration**: Automatically restores sessions within 15 minutes
236
- 2. **Activity Tracking**: Updates activity timestamp on user interactions
237
- 3. **Cross-Page Persistence**: Session persists across page navigations
238
-
239
- ## Demo
240
-
241
- Check out `simple-spa.html` for a complete single-page application demo that shows:
242
-
243
- - True session continuity across navigation
244
- - Interactive event tracking
245
- - Real-time status updates
246
- - Modern UI with smooth transitions
247
-
248
- ## Troubleshooting
249
-
250
- ### Ad Blocker Issues
251
-
252
- If you see `net::ERR_BLOCKED_BY_CLIENT` errors:
253
-
254
- 1. Check if ad blockers are active
255
- 2. Use `tracker.getConnectionStatus()` to diagnose
256
- 3. Consider whitelisting your domain
257
-
258
- ### Session Issues
259
-
260
- - Sessions automatically expire after 15 minutes of inactivity
261
- - Each page load calls `/init` but reuses existing sessions when possible
262
- - Check browser console for session restoration logs
263
-
264
- ## Development
265
-
266
- ```bash
267
- # Build the SDK
268
- npm run build
269
-
270
- # Watch for changes
271
- npm run dev
272
-
273
- # Run tests
274
- npm test
275
-
276
- # Run auto-installation
277
- npm run auto-install
278
- ```
279
-
280
- ## Auto-Installation Wizard
281
-
282
- The SDK includes an auto-installation wizard that can detect your project's framework and automatically modify your codebase to integrate the SDK.
283
-
284
- ### CLI Usage
285
-
286
- ```bash
287
- # Basic usage
288
- npx humanbehavior-js auto-install YOUR_API_KEY
289
-
290
- # With options
291
- npx humanbehavior-js auto-install YOUR_API_KEY --yes --project /path/to/project
292
-
293
- # Help
294
- npx humanbehavior-js auto-install --help
295
- ```
296
-
297
- ### React Component Usage
298
-
299
- ```jsx
300
- import { AutoInstallWizard } from 'humanbehavior-js/react';
301
-
302
- function Dashboard() {
303
- return (
304
- <AutoInstallWizard
305
- apiKey="your-api-key"
306
- onComplete={(result) => console.log('Installation completed!', result)}
307
- onError={(error) => console.error('Installation failed:', error)}
308
- />
309
- );
310
- }
311
- ```
312
-
313
- ### Supported Frameworks
314
-
315
- - ✅ React (CRA, Vite, Webpack)
316
- - ✅ Next.js (App Router, Pages Router)
317
- - ✅ Vue (Vue CLI, Vite)
318
- - ✅ Angular
319
- - ✅ Svelte (SvelteKit, Vite)
320
- - ✅ Vanilla JS/TS
321
- - ✅ Node.js (CommonJS & ESM)
322
-
323
- The wizard will automatically:
324
- 1. Detect your project's framework and setup
325
- 2. Install the humanbehavior-js package
326
- 3. Modify your main app files to integrate the SDK
327
- 4. Create environment files with your API key
328
- 5. Make your app ready to track user behavior
329
-
330
- ## Architecture
331
-
332
- - **Frontend**: TypeScript SDK with session restoration
333
- - **Backend**: Node.js ingestion server with Redis storage
334
- - **Archiver**: Processes completed sessions to S3 and Prisma
335
- - **Session Continuity**: localStorage + cookie-based session management