humanbehavior-js 0.4.3 → 0.4.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.
@@ -13241,27 +13241,27 @@ class HumanBehaviorTracker {
13241
13241
  this.redactionManager = new RedactionManager();
13242
13242
  // Handle session restoration with improved continuity
13243
13243
  if (isBrowser) {
13244
- const existingSessionId = localStorage.getItem('human_behavior_session_id');
13245
- const lastActivity = localStorage.getItem('human_behavior_last_activity');
13244
+ const existingSessionId = localStorage.getItem(`human_behavior_session_id_${this.apiKey}`);
13245
+ const lastActivity = localStorage.getItem(`human_behavior_last_activity_${this.apiKey}`);
13246
13246
  const fifteenMinutesAgo = Date.now() - (15 * 60 * 1000);
13247
13247
  // Check if we have an existing session that's still within the activity window
13248
13248
  if (existingSessionId && lastActivity && parseInt(lastActivity) > fifteenMinutesAgo) {
13249
13249
  this.sessionId = existingSessionId;
13250
13250
  logDebug(`Reusing existing session: ${this.sessionId}`);
13251
13251
  // Update activity timestamp to extend the session window
13252
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
13252
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
13253
13253
  }
13254
13254
  else {
13255
13255
  // Clear old session data if it's expired
13256
13256
  if (existingSessionId) {
13257
13257
  logDebug(`Session expired, clearing old session: ${existingSessionId}`);
13258
- localStorage.removeItem('human_behavior_session_id');
13259
- localStorage.removeItem('human_behavior_last_activity');
13258
+ localStorage.removeItem(`human_behavior_session_id_${this.apiKey}`);
13259
+ localStorage.removeItem(`human_behavior_last_activity_${this.apiKey}`);
13260
13260
  }
13261
13261
  this.sessionId = v1();
13262
13262
  logDebug(`Creating new session: ${this.sessionId}`);
13263
- localStorage.setItem('human_behavior_session_id', this.sessionId);
13264
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
13263
+ localStorage.setItem(`human_behavior_session_id_${this.apiKey}`, this.sessionId);
13264
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
13265
13265
  }
13266
13266
  this.currentUrl = window.location.href;
13267
13267
  window.__humanBehaviorGlobalTracker = this;
@@ -13284,7 +13284,7 @@ class HumanBehaviorTracker {
13284
13284
  this.sessionId = sessionId;
13285
13285
  // Update localStorage with server's session ID for continuity
13286
13286
  if (isBrowser) {
13287
- localStorage.setItem('human_behavior_session_id', this.sessionId);
13287
+ localStorage.setItem(`human_behavior_session_id_${this.apiKey}`, this.sessionId);
13288
13288
  }
13289
13289
  }
13290
13290
  this.endUserId = endUserId;
@@ -13725,7 +13725,7 @@ class HumanBehaviorTracker {
13725
13725
  });
13726
13726
  // Update activity timestamp on user interaction (not on page load)
13727
13727
  const updateActivity = () => {
13728
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
13728
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
13729
13729
  };
13730
13730
  // Listen for user interactions to update activity timestamp
13731
13731
  window.addEventListener('click', updateActivity);
@@ -14029,16 +14029,16 @@ class HumanBehaviorTracker {
14029
14029
  const userIdCookieName = `human_behavior_end_user_id_${this.apiKey}`;
14030
14030
  this.deleteCookie(userIdCookieName);
14031
14031
  // Clear session data from localStorage
14032
- localStorage.removeItem('human_behavior_session_id');
14033
- localStorage.removeItem('human_behavior_last_activity');
14032
+ localStorage.removeItem(`human_behavior_session_id_${this.apiKey}`);
14033
+ localStorage.removeItem(`human_behavior_last_activity_${this.apiKey}`);
14034
14034
  // Reset user-related properties
14035
14035
  this.endUserId = null;
14036
14036
  this.userProperties = {};
14037
14037
  // Generate a new session ID for the next user
14038
14038
  this.sessionId = v1();
14039
14039
  if (isBrowser) {
14040
- localStorage.setItem('human_behavior_session_id', this.sessionId);
14041
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
14040
+ localStorage.setItem(`human_behavior_session_id_${this.apiKey}`, this.sessionId);
14041
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
14042
14042
  }
14043
14043
  logInfo('User logged out - cleared all user data and started fresh session');
14044
14044
  }