humanbehavior-js 0.2.2 → 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/cjs/index.js +26 -27
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +26 -27
- package/dist/esm/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/types/index.d.ts +8 -5
- package/package.json +1 -1
- package/simple-spa.html +184 -4
- package/src/api.ts +13 -6
- package/src/tracker.ts +22 -22
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/.tsbuildinfo +0 -1
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/api.js +0 -312
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/api.js.map +0 -1
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/index.js +0 -19
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/index.js.map +0 -1
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/react/index.js +0 -222
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/react/index.js.map +0 -1
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/redact.js +0 -416
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/redact.js.map +0 -1
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/tracker.js +0 -950
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/tracker.js.map +0 -1
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/utils/logger.js +0 -117
- package/.rollup.cache/Users/hudsonch/Desktop/HumanBehaviorInternship/humanbehavior-js/dist/utils/logger.js.map +0 -1
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
|
-
|
|
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);
|
|
@@ -5474,35 +5479,29 @@ class HumanBehaviorTracker {
|
|
|
5474
5479
|
logError('Failed to read logs:', e);
|
|
5475
5480
|
}
|
|
5476
5481
|
}
|
|
5482
|
+
/**
|
|
5483
|
+
* Add user identification information to the tracker
|
|
5484
|
+
* If userId is not provided, will use userProperties.email as the userId (if present)
|
|
5485
|
+
*/
|
|
5477
5486
|
addUserInfo(_a) {
|
|
5478
5487
|
return __awaiter$1(this, arguments, void 0, function* ({ userId, userProperties }) {
|
|
5479
5488
|
yield this.ensureInitialized();
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5489
|
+
// Keep the original endUserId (UUID) - don't change it
|
|
5490
|
+
const originalEndUserId = this.endUserId;
|
|
5491
|
+
// Store user properties
|
|
5483
5492
|
this.userProperties = userProperties;
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
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 || '';
|
|
5488
5498
|
});
|
|
5489
5499
|
}
|
|
5490
5500
|
/**
|
|
5491
|
-
*
|
|
5492
|
-
* @param authFields Array of field names to check for existing users (e.g., ['email', 'phoneNumber'])
|
|
5501
|
+
* Get current user attributes
|
|
5493
5502
|
*/
|
|
5494
|
-
|
|
5495
|
-
return
|
|
5496
|
-
yield this.ensureInitialized();
|
|
5497
|
-
if (!this.endUserId) {
|
|
5498
|
-
throw new Error('Cannot authenticate before tracker initialization');
|
|
5499
|
-
}
|
|
5500
|
-
const response = yield this.api.sendUserAuth(this.endUserId, { id }, this.sessionId, ["id"]);
|
|
5501
|
-
if (response && response.userId && response.userId !== this.endUserId) {
|
|
5502
|
-
this.endUserId = response.userId;
|
|
5503
|
-
this.setCookie(`human_behavior_end_user_id_${this.apiKey}`, response.userId, 365);
|
|
5504
|
-
}
|
|
5505
|
-
});
|
|
5503
|
+
getUserAttributes() {
|
|
5504
|
+
return Object.assign({}, this.userProperties);
|
|
5506
5505
|
}
|
|
5507
5506
|
start() {
|
|
5508
5507
|
return __awaiter$1(this, void 0, void 0, function* () {
|