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