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.
package/dist/esm/index.js CHANGED
@@ -5560,6 +5560,10 @@ class HumanBehaviorTracker {
5560
5560
  emit: (event) => {
5561
5561
  // ✅ DIRECT EVENT HANDLING - Let rrweb handle events natively
5562
5562
  this.addEvent(event);
5563
+ // ✅ DEBUG FULLSNAPSHOT GENERATION
5564
+ if (event.type === 2) { // FullSnapshot
5565
+ logDebug(`🎯 FullSnapshot generated at ${new Date().toISOString()}`);
5566
+ }
5563
5567
  },
5564
5568
  inlineStylesheet: true,
5565
5569
  recordCanvas: true,
@@ -5571,6 +5575,9 @@ class HumanBehaviorTracker {
5571
5575
  // ✅ RRWEB BUILT-IN MASKING - More reliable than custom redaction
5572
5576
  maskAllInputs: false, // Let users control this via selectors
5573
5577
  maskTextSelector: this.redactionManager.getMaskTextSelector() || undefined,
5578
+ // ✅ FULLSNAPSHOT GENERATION - Use reasonable intervals (PostHog-style)
5579
+ checkoutEveryNms: 300000, // Take FullSnapshot every 5 minutes (like PostHog)
5580
+ checkoutEveryNth: 1000, // Take FullSnapshot every 1000 events
5574
5581
  // ✅ SELECTOR-BASED REDACTION - Users control via CSS selectors
5575
5582
  // No custom masking functions needed - rrweb handles this natively
5576
5583
  });
@@ -5848,15 +5855,15 @@ class HumanBehaviorTracker {
5848
5855
  }
5849
5856
  /**
5850
5857
  * Get current snapshot frequency info
5851
- * Uses rrweb's sensible defaults (5 seconds, 100 events)
5858
+ * Uses configured values (5 minutes, 1000 events) - PostHog-style
5852
5859
  */
5853
5860
  getSnapshotFrequencyInfo() {
5854
5861
  const sessionDuration = Date.now() - this.sessionStartTime;
5855
5862
  return {
5856
5863
  sessionDuration,
5857
- currentInterval: 5000, // rrweb default - 5 seconds
5858
- currentThreshold: 100, // rrweb default - 100 events
5859
- phase: 'default' // Using rrweb's proven defaults
5864
+ currentInterval: 300000, // Configured - 5 minutes (PostHog-style)
5865
+ currentThreshold: 1000, // Configured - 1000 events
5866
+ phase: 'configured' // Using explicit configuration
5860
5867
  };
5861
5868
  }
5862
5869
  /**
@@ -5931,57 +5938,6 @@ if (isBrowser) {
5931
5938
  window.HumanBehaviorTracker = HumanBehaviorTracker;
5932
5939
  }
5933
5940
 
5934
- /**
5935
- * Server-side utilities for HumanBehavior SDK
5936
- */
5937
- /**
5938
- * Identify user from server-side (NextAuth, Firebase, etc.)
5939
- * Use this in your auth events to track users immediately on sign-in
5940
- */
5941
- function identifyUser(userId, // Separate userId parameter (should be stable unique identifier)
5942
- userData, apiKey) {
5943
- return __awaiter$1(this, void 0, void 0, function* () {
5944
- try {
5945
- const response = yield fetch('https://ingest.humanbehavior.co/api/ingestion/user', {
5946
- method: 'POST',
5947
- headers: {
5948
- 'Content-Type': 'application/json',
5949
- 'Authorization': `Bearer ${apiKey}`
5950
- },
5951
- body: JSON.stringify({
5952
- userId: userId, // Use stable unique identifier
5953
- userAttributes: userData, // Email and other data go here
5954
- sessionId: 'server-side-identification', // Dummy sessionId for server-side requests
5955
- posthogName: userData.email || userData.name || null // Update posthogName with email
5956
- })
5957
- });
5958
- if (!response.ok) {
5959
- const errorText = yield response.text();
5960
- return {
5961
- success: false,
5962
- error: `Failed to identify user: ${response.status} ${response.statusText} - ${errorText}`
5963
- };
5964
- }
5965
- const result = yield response.json();
5966
- // If server found existing user, return the actual userId
5967
- if (result.actualUserId && result.actualUserId !== userId) {
5968
- console.log(`🔄 Server found existing user: ${result.actualUserId} (sent: ${userId})`);
5969
- return {
5970
- success: true,
5971
- actualUserId: result.actualUserId
5972
- };
5973
- }
5974
- return { success: true };
5975
- }
5976
- catch (error) {
5977
- return {
5978
- success: false,
5979
- error: error instanceof Error ? error.message : 'Unknown error'
5980
- };
5981
- }
5982
- });
5983
- }
5984
-
5985
5941
  /**
5986
5942
  * Main entry point for the HumanBehavior SDK
5987
5943
  */
@@ -5990,5 +5946,5 @@ if (typeof window !== 'undefined') {
5990
5946
  window.HumanBehaviorTracker = HumanBehaviorTracker;
5991
5947
  }
5992
5948
 
5993
- export { HumanBehaviorAPI, HumanBehaviorTracker, LogLevel, MAX_CHUNK_SIZE_BYTES, RedactionManager, HumanBehaviorTracker as default, identifyUser, isChunkSizeExceeded, logDebug, logError, logInfo, logWarn, logger, redactionManager, splitLargeEvent, validateSingleEventSize };
5949
+ export { HumanBehaviorAPI, HumanBehaviorTracker, LogLevel, MAX_CHUNK_SIZE_BYTES, RedactionManager, HumanBehaviorTracker as default, isChunkSizeExceeded, logDebug, logError, logInfo, logWarn, logger, redactionManager, splitLargeEvent, validateSingleEventSize };
5994
5950
  //# sourceMappingURL=index.js.map