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