humanbehavior-js 0.2.1 → 0.2.3

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/cjs/index.js CHANGED
@@ -3234,17 +3234,13 @@ function initCanvasWebGLMutationObserver(cb, win, blockClass, blockSelector, mir
3234
3234
  };
3235
3235
  }
3236
3236
 
3237
- function commonjsRequire(path) {
3238
- throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
3239
- }
3240
-
3241
3237
  var WorkerClass = null;
3242
3238
 
3243
3239
  try {
3244
3240
  var WorkerThreads =
3245
- typeof module !== 'undefined' && typeof commonjsRequire === 'function' && module.require('worker_threads') ||
3241
+ typeof module !== 'undefined' && typeof module.require === 'function' && module.require('worker_threads') ||
3246
3242
  typeof __non_webpack_require__ === 'function' && __non_webpack_require__('worker_threads') ||
3247
- typeof commonjsRequire === 'function' && require('worker_threads');
3243
+ typeof require === 'function' && require('worker_threads');
3248
3244
  WorkerClass = WorkerThreads.Worker;
3249
3245
  } catch(e) {} // eslint-disable-line
3250
3246
 
@@ -5482,34 +5478,26 @@ class HumanBehaviorTracker {
5482
5478
  logError('Failed to read logs:', e);
5483
5479
  }
5484
5480
  }
5485
- addUserInfo(_a) {
5486
- return __awaiter$1(this, arguments, void 0, function* ({ userId, userProperties }) {
5487
- yield this.ensureInitialized();
5488
- if (!this.endUserId) {
5489
- throw new Error('Cannot add user info before tracker initialization');
5490
- }
5491
- this.userProperties = userProperties;
5492
- yield this.api.sendUserData(this.endUserId, userProperties, this.sessionId);
5493
- if (userId) {
5494
- this.endUserId = userId;
5495
- }
5496
- });
5497
- }
5498
5481
  /**
5499
5482
  * Add user identification information to the tracker
5500
- * @param authFields Array of field names to check for existing users (e.g., ['email', 'phoneNumber'])
5483
+ * If userId is not provided, will use userProperties.email as the userId (if present)
5501
5484
  */
5502
- auth(id) {
5503
- return __awaiter$1(this, void 0, void 0, function* () {
5485
+ addUserInfo(_a) {
5486
+ return __awaiter$1(this, arguments, void 0, function* ({ userId, userProperties }) {
5504
5487
  yield this.ensureInitialized();
5505
- if (!this.endUserId) {
5506
- throw new Error('Cannot authenticate before tracker initialization');
5488
+ // Determine the userId to use
5489
+ const resolvedUserId = userId || userProperties.email;
5490
+ if (!resolvedUserId) {
5491
+ return this.endUserId || '';
5507
5492
  }
5508
- const response = yield this.api.sendUserAuth(this.endUserId, { id }, this.sessionId, ["id"]);
5509
- if (response && response.userId && response.userId !== this.endUserId) {
5510
- this.endUserId = response.userId;
5511
- this.setCookie(`human_behavior_end_user_id_${this.apiKey}`, response.userId, 365);
5493
+ this.userProperties = userProperties;
5494
+ yield this.api.sendUserData(resolvedUserId, userProperties, this.sessionId);
5495
+ // Update endUserId and cookie if changed
5496
+ if (resolvedUserId !== this.endUserId) {
5497
+ this.endUserId = resolvedUserId;
5498
+ this.setCookie(`human_behavior_end_user_id_${this.apiKey}`, resolvedUserId, 365);
5512
5499
  }
5500
+ return this.endUserId || '';
5513
5501
  });
5514
5502
  }
5515
5503
  start() {