humanbehavior-js 0.2.3 → 0.2.4

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
@@ -4351,22 +4351,27 @@ class HumanBehaviorAPI {
4351
4351
  sendUserData(userId, userData, sessionId) {
4352
4352
  return __awaiter$1(this, void 0, void 0, function* () {
4353
4353
  try {
4354
+ const payload = {
4355
+ userId: userId,
4356
+ userAttributes: userData,
4357
+ sessionId: sessionId,
4358
+ posthogName: userData.email || userData.name || null // Update posthogName with email
4359
+ };
4360
+ console.log('Sending user data to server:', payload);
4354
4361
  const response = yield fetch(`${this.baseUrl}/api/ingestion/user`, {
4355
4362
  method: 'POST',
4356
4363
  headers: {
4357
4364
  'Content-Type': 'application/json',
4358
4365
  'Authorization': `Bearer ${this.apiKey}`
4359
4366
  },
4360
- body: JSON.stringify({
4361
- userId: userId,
4362
- userAttributes: userData,
4363
- sessionId: sessionId
4364
- })
4367
+ body: JSON.stringify(payload)
4365
4368
  });
4366
4369
  if (!response.ok) {
4367
4370
  throw new Error(`Failed to send user data: ${response.statusText} with API key: ${this.apiKey}`);
4368
4371
  }
4369
- return yield response.json();
4372
+ const result = yield response.json();
4373
+ console.log('Server response:', result);
4374
+ return result;
4370
4375
  }
4371
4376
  catch (error) {
4372
4377
  logError('Error sending user data:', error);
@@ -5481,21 +5486,23 @@ class HumanBehaviorTracker {
5481
5486
  addUserInfo(_a) {
5482
5487
  return __awaiter$1(this, arguments, void 0, function* ({ userId, userProperties }) {
5483
5488
  yield this.ensureInitialized();
5484
- // Determine the userId to use
5485
- const resolvedUserId = userId || userProperties.email;
5486
- if (!resolvedUserId) {
5487
- return this.endUserId || '';
5488
- }
5489
+ // Keep the original endUserId (UUID) - don't change it
5490
+ const originalEndUserId = this.endUserId;
5491
+ // Store user properties
5489
5492
  this.userProperties = userProperties;
5490
- yield this.api.sendUserData(resolvedUserId, userProperties, this.sessionId);
5491
- // Update endUserId and cookie if changed
5492
- if (resolvedUserId !== this.endUserId) {
5493
- this.endUserId = resolvedUserId;
5494
- this.setCookie(`human_behavior_end_user_id_${this.apiKey}`, resolvedUserId, 365);
5495
- }
5496
- return this.endUserId || '';
5493
+ // Send user data with the original endUserId
5494
+ yield this.api.sendUserData(originalEndUserId, userProperties, this.sessionId);
5495
+ // Don't update endUserId - keep it as the original UUID
5496
+ // The posthogName will be updated on the server side with the email
5497
+ return originalEndUserId || '';
5497
5498
  });
5498
5499
  }
5500
+ /**
5501
+ * Get current user attributes
5502
+ */
5503
+ getUserAttributes() {
5504
+ return Object.assign({}, this.userProperties);
5505
+ }
5499
5506
  start() {
5500
5507
  return __awaiter$1(this, void 0, void 0, function* () {
5501
5508
  yield this.ensureInitialized();