humanbehavior-js 0.4.4 → 0.4.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "humanbehavior-js",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "SDK for HumanBehavior session and event recording",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
package/src/tracker.ts CHANGED
@@ -126,8 +126,8 @@ export class HumanBehaviorTracker {
126
126
 
127
127
  // Handle session restoration with improved continuity
128
128
  if (isBrowser) {
129
- const existingSessionId = localStorage.getItem('human_behavior_session_id');
130
- const lastActivity = localStorage.getItem('human_behavior_last_activity');
129
+ const existingSessionId = localStorage.getItem(`human_behavior_session_id_${this.apiKey}`);
130
+ const lastActivity = localStorage.getItem(`human_behavior_last_activity_${this.apiKey}`);
131
131
  const fifteenMinutesAgo = Date.now() - (15 * 60 * 1000);
132
132
 
133
133
  // Check if we have an existing session that's still within the activity window
@@ -135,18 +135,18 @@ export class HumanBehaviorTracker {
135
135
  this.sessionId = existingSessionId;
136
136
  logDebug(`Reusing existing session: ${this.sessionId}`);
137
137
  // Update activity timestamp to extend the session window
138
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
138
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
139
139
  } else {
140
140
  // Clear old session data if it's expired
141
141
  if (existingSessionId) {
142
142
  logDebug(`Session expired, clearing old session: ${existingSessionId}`);
143
- localStorage.removeItem('human_behavior_session_id');
144
- localStorage.removeItem('human_behavior_last_activity');
143
+ localStorage.removeItem(`human_behavior_session_id_${this.apiKey}`);
144
+ localStorage.removeItem(`human_behavior_last_activity_${this.apiKey}`);
145
145
  }
146
146
  this.sessionId = uuidv1();
147
147
  logDebug(`Creating new session: ${this.sessionId}`);
148
- localStorage.setItem('human_behavior_session_id', this.sessionId);
149
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
148
+ localStorage.setItem(`human_behavior_session_id_${this.apiKey}`, this.sessionId);
149
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
150
150
  }
151
151
 
152
152
  this.currentUrl = window.location.href;
@@ -172,7 +172,7 @@ export class HumanBehaviorTracker {
172
172
  this.sessionId = sessionId;
173
173
  // Update localStorage with server's session ID for continuity
174
174
  if (isBrowser) {
175
- localStorage.setItem('human_behavior_session_id', this.sessionId);
175
+ localStorage.setItem(`human_behavior_session_id_${this.apiKey}`, this.sessionId);
176
176
  }
177
177
  }
178
178
 
@@ -693,7 +693,7 @@ export class HumanBehaviorTracker {
693
693
 
694
694
  // Update activity timestamp on user interaction (not on page load)
695
695
  const updateActivity = () => {
696
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
696
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
697
697
  };
698
698
 
699
699
  // Listen for user interactions to update activity timestamp
@@ -785,8 +785,8 @@ export class HumanBehaviorTracker {
785
785
  recordCanvas: false, // Disabled to prevent large data URIs
786
786
 
787
787
  // ✅ FULLSNAPSHOT GENERATION - Use reasonable intervals
788
- checkoutEveryNms: 300000, // Take FullSnapshot every 5 minutes
789
- checkoutEveryNth: 1000, // Take FullSnapshot every 1000 events
788
+ // checkoutEveryNms: 300000, // Take FullSnapshot every 5 minutes
789
+ // checkoutEveryNth: 1000, // Take FullSnapshot every 1000 events
790
790
  });
791
791
 
792
792
  // Store the record instance for cleanup
@@ -1013,8 +1013,8 @@ export class HumanBehaviorTracker {
1013
1013
  this.deleteCookie(userIdCookieName);
1014
1014
 
1015
1015
  // Clear session data from localStorage
1016
- localStorage.removeItem('human_behavior_session_id');
1017
- localStorage.removeItem('human_behavior_last_activity');
1016
+ localStorage.removeItem(`human_behavior_session_id_${this.apiKey}`);
1017
+ localStorage.removeItem(`human_behavior_last_activity_${this.apiKey}`);
1018
1018
 
1019
1019
  // Reset user-related properties
1020
1020
  this.endUserId = null;
@@ -1023,8 +1023,8 @@ export class HumanBehaviorTracker {
1023
1023
  // Generate a new session ID for the next user
1024
1024
  this.sessionId = uuidv1();
1025
1025
  if (isBrowser) {
1026
- localStorage.setItem('human_behavior_session_id', this.sessionId);
1027
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
1026
+ localStorage.setItem(`human_behavior_session_id_${this.apiKey}`, this.sessionId);
1027
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
1028
1028
  }
1029
1029
 
1030
1030
  logInfo('User logged out - cleared all user data and started fresh session');