humanbehavior-js 0.3.3 → 0.3.5

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.
@@ -262,7 +262,7 @@ declare class HumanBehaviorTracker {
262
262
  getCurrentUrl(): string;
263
263
  /**
264
264
  * Get current snapshot frequency info
265
- * Uses rrweb's sensible defaults (5 seconds, 100 events)
265
+ * Uses configured values (5 minutes, 1000 events) - PostHog-style
266
266
  */
267
267
  getSnapshotFrequencyInfo(): {
268
268
  sessionDuration: number;
@@ -327,27 +327,6 @@ declare class HumanBehaviorAPI {
327
327
  }>): Promise<any>;
328
328
  }
329
329
 
330
- /**
331
- * Server-side utilities for HumanBehavior SDK
332
- */
333
- interface ServerSideUserData {
334
- email: string;
335
- name?: string;
336
- image?: string;
337
- provider?: string;
338
- [key: string]: any;
339
- }
340
- /**
341
- * Identify user from server-side (NextAuth, Firebase, etc.)
342
- * Use this in your auth events to track users immediately on sign-in
343
- */
344
- declare function identifyUser(userId: string, // Separate userId parameter (should be stable unique identifier)
345
- userData: ServerSideUserData, apiKey: string): Promise<{
346
- success: boolean;
347
- error?: string;
348
- actualUserId?: string;
349
- }>;
350
-
351
330
  declare enum LogLevel {
352
331
  NONE = 0,
353
332
  ERROR = 1,
@@ -381,5 +360,5 @@ declare const logWarn: (message: string, ...args: any[]) => void;
381
360
  declare const logInfo: (message: string, ...args: any[]) => void;
382
361
  declare const logDebug: (message: string, ...args: any[]) => void;
383
362
 
384
- export { HumanBehaviorAPI, HumanBehaviorTracker, LogLevel, MAX_CHUNK_SIZE_BYTES, RedactionManager, HumanBehaviorTracker as default, identifyUser, isChunkSizeExceeded, logDebug, logError, logInfo, logWarn, logger, redactionManager, splitLargeEvent, validateSingleEventSize };
385
- export type { LoggerConfig, RedactionOptions, ServerSideUserData };
363
+ export { HumanBehaviorAPI, HumanBehaviorTracker, LogLevel, MAX_CHUNK_SIZE_BYTES, RedactionManager, HumanBehaviorTracker as default, isChunkSizeExceeded, logDebug, logError, logInfo, logWarn, logger, redactionManager, splitLargeEvent, validateSingleEventSize };
364
+ export type { LoggerConfig, RedactionOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "humanbehavior-js",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "SDK for HumanBehavior session and event recording",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
package/src/index.ts CHANGED
@@ -13,9 +13,6 @@ export * from './api';
13
13
  // Export redaction functionality
14
14
  export * from './redact';
15
15
 
16
- // Export server-side utilities
17
- export * from './server';
18
-
19
16
  // Export logger functionality
20
17
  export * from './utils/logger';
21
18
 
package/src/tracker.ts CHANGED
@@ -760,6 +760,11 @@ export class HumanBehaviorTracker {
760
760
  emit: (event) => {
761
761
  // ✅ DIRECT EVENT HANDLING - Let rrweb handle events natively
762
762
  this.addEvent(event);
763
+
764
+ // ✅ DEBUG FULLSNAPSHOT GENERATION
765
+ if (event.type === 2) { // FullSnapshot
766
+ logDebug(`🎯 FullSnapshot generated at ${new Date().toISOString()}`);
767
+ }
763
768
  },
764
769
  inlineStylesheet: true,
765
770
  recordCanvas: true,
@@ -773,6 +778,10 @@ export class HumanBehaviorTracker {
773
778
  maskAllInputs: false, // Let users control this via selectors
774
779
  maskTextSelector: this.redactionManager.getMaskTextSelector() || undefined,
775
780
 
781
+ // ✅ FULLSNAPSHOT GENERATION - Use reasonable intervals (PostHog-style)
782
+ checkoutEveryNms: 300000, // Take FullSnapshot every 5 minutes (like PostHog)
783
+ checkoutEveryNth: 1000, // Take FullSnapshot every 1000 events
784
+
776
785
  // ✅ SELECTOR-BASED REDACTION - Users control via CSS selectors
777
786
  // No custom masking functions needed - rrweb handles this natively
778
787
  });
@@ -1063,7 +1072,7 @@ export class HumanBehaviorTracker {
1063
1072
 
1064
1073
  /**
1065
1074
  * Get current snapshot frequency info
1066
- * Uses rrweb's sensible defaults (5 seconds, 100 events)
1075
+ * Uses configured values (5 minutes, 1000 events) - PostHog-style
1067
1076
  */
1068
1077
  public getSnapshotFrequencyInfo(): {
1069
1078
  sessionDuration: number;
@@ -1075,9 +1084,9 @@ export class HumanBehaviorTracker {
1075
1084
 
1076
1085
  return {
1077
1086
  sessionDuration,
1078
- currentInterval: 5000, // rrweb default - 5 seconds
1079
- currentThreshold: 100, // rrweb default - 100 events
1080
- phase: 'default' // Using rrweb's proven defaults
1087
+ currentInterval: 300000, // Configured - 5 minutes (PostHog-style)
1088
+ currentThreshold: 1000, // Configured - 1000 events
1089
+ phase: 'configured' // Using explicit configuration
1081
1090
  };
1082
1091
  }
1083
1092
 
package/src/server.ts DELETED
@@ -1,63 +0,0 @@
1
- /**
2
- * Server-side utilities for HumanBehavior SDK
3
- */
4
-
5
- export interface ServerSideUserData {
6
- email: string;
7
- name?: string;
8
- image?: string;
9
- provider?: string;
10
- [key: string]: any; // Allow additional properties
11
- }
12
-
13
- /**
14
- * Identify user from server-side (NextAuth, Firebase, etc.)
15
- * Use this in your auth events to track users immediately on sign-in
16
- */
17
- export async function identifyUser(
18
- userId: string, // Separate userId parameter (should be stable unique identifier)
19
- userData: ServerSideUserData,
20
- apiKey: string
21
- ): Promise<{ success: boolean; error?: string; actualUserId?: string }> {
22
- try {
23
- const response = await fetch('https://ingest.humanbehavior.co/api/ingestion/user', {
24
- method: 'POST',
25
- headers: {
26
- 'Content-Type': 'application/json',
27
- 'Authorization': `Bearer ${apiKey}`
28
- },
29
- body: JSON.stringify({
30
- userId: userId, // Use stable unique identifier
31
- userAttributes: userData, // Email and other data go here
32
- sessionId: 'server-side-identification', // Dummy sessionId for server-side requests
33
- posthogName: userData.email || userData.name || null // Update posthogName with email
34
- })
35
- });
36
-
37
- if (!response.ok) {
38
- const errorText = await response.text();
39
- return {
40
- success: false,
41
- error: `Failed to identify user: ${response.status} ${response.statusText} - ${errorText}`
42
- };
43
- }
44
-
45
- const result = await response.json();
46
-
47
- // If server found existing user, return the actual userId
48
- if (result.actualUserId && result.actualUserId !== userId) {
49
- console.log(`🔄 Server found existing user: ${result.actualUserId} (sent: ${userId})`);
50
- return {
51
- success: true,
52
- actualUserId: result.actualUserId
53
- };
54
- }
55
-
56
- return { success: true };
57
- } catch (error) {
58
- return {
59
- success: false,
60
- error: error instanceof Error ? error.message : 'Unknown error'
61
- };
62
- }
63
- }