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