humanbehavior-js 0.4.4 → 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.
@@ -13253,27 +13253,27 @@ class HumanBehaviorTracker {
13253
13253
  this.redactionManager = new RedactionManager();
13254
13254
  // Handle session restoration with improved continuity
13255
13255
  if (isBrowser) {
13256
- const existingSessionId = localStorage.getItem('human_behavior_session_id');
13257
- const lastActivity = localStorage.getItem('human_behavior_last_activity');
13256
+ const existingSessionId = localStorage.getItem(`human_behavior_session_id_${this.apiKey}`);
13257
+ const lastActivity = localStorage.getItem(`human_behavior_last_activity_${this.apiKey}`);
13258
13258
  const fifteenMinutesAgo = Date.now() - (15 * 60 * 1000);
13259
13259
  // Check if we have an existing session that's still within the activity window
13260
13260
  if (existingSessionId && lastActivity && parseInt(lastActivity) > fifteenMinutesAgo) {
13261
13261
  this.sessionId = existingSessionId;
13262
13262
  logDebug(`Reusing existing session: ${this.sessionId}`);
13263
13263
  // Update activity timestamp to extend the session window
13264
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
13264
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
13265
13265
  }
13266
13266
  else {
13267
13267
  // Clear old session data if it's expired
13268
13268
  if (existingSessionId) {
13269
13269
  logDebug(`Session expired, clearing old session: ${existingSessionId}`);
13270
- localStorage.removeItem('human_behavior_session_id');
13271
- localStorage.removeItem('human_behavior_last_activity');
13270
+ localStorage.removeItem(`human_behavior_session_id_${this.apiKey}`);
13271
+ localStorage.removeItem(`human_behavior_last_activity_${this.apiKey}`);
13272
13272
  }
13273
13273
  this.sessionId = v1();
13274
13274
  logDebug(`Creating new session: ${this.sessionId}`);
13275
- localStorage.setItem('human_behavior_session_id', this.sessionId);
13276
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
13275
+ localStorage.setItem(`human_behavior_session_id_${this.apiKey}`, this.sessionId);
13276
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
13277
13277
  }
13278
13278
  this.currentUrl = window.location.href;
13279
13279
  window.__humanBehaviorGlobalTracker = this;
@@ -13296,7 +13296,7 @@ class HumanBehaviorTracker {
13296
13296
  this.sessionId = sessionId;
13297
13297
  // Update localStorage with server's session ID for continuity
13298
13298
  if (isBrowser) {
13299
- localStorage.setItem('human_behavior_session_id', this.sessionId);
13299
+ localStorage.setItem(`human_behavior_session_id_${this.apiKey}`, this.sessionId);
13300
13300
  }
13301
13301
  }
13302
13302
  this.endUserId = endUserId;
@@ -13737,7 +13737,7 @@ class HumanBehaviorTracker {
13737
13737
  });
13738
13738
  // Update activity timestamp on user interaction (not on page load)
13739
13739
  const updateActivity = () => {
13740
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
13740
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
13741
13741
  };
13742
13742
  // Listen for user interactions to update activity timestamp
13743
13743
  window.addEventListener('click', updateActivity);
@@ -14041,16 +14041,16 @@ class HumanBehaviorTracker {
14041
14041
  const userIdCookieName = `human_behavior_end_user_id_${this.apiKey}`;
14042
14042
  this.deleteCookie(userIdCookieName);
14043
14043
  // Clear session data from localStorage
14044
- localStorage.removeItem('human_behavior_session_id');
14045
- localStorage.removeItem('human_behavior_last_activity');
14044
+ localStorage.removeItem(`human_behavior_session_id_${this.apiKey}`);
14045
+ localStorage.removeItem(`human_behavior_last_activity_${this.apiKey}`);
14046
14046
  // Reset user-related properties
14047
14047
  this.endUserId = null;
14048
14048
  this.userProperties = {};
14049
14049
  // Generate a new session ID for the next user
14050
14050
  this.sessionId = v1();
14051
14051
  if (isBrowser) {
14052
- localStorage.setItem('human_behavior_session_id', this.sessionId);
14053
- localStorage.setItem('human_behavior_last_activity', Date.now().toString());
14052
+ localStorage.setItem(`human_behavior_session_id_${this.apiKey}`, this.sessionId);
14053
+ localStorage.setItem(`human_behavior_last_activity_${this.apiKey}`, Date.now().toString());
14054
14054
  }
14055
14055
  logInfo('User logged out - cleared all user data and started fresh session');
14056
14056
  }