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/cjs/index.js
CHANGED
|
@@ -4355,22 +4355,27 @@ class HumanBehaviorAPI {
|
|
|
4355
4355
|
sendUserData(userId, userData, sessionId) {
|
|
4356
4356
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
4357
4357
|
try {
|
|
4358
|
+
const payload = {
|
|
4359
|
+
userId: userId,
|
|
4360
|
+
userAttributes: userData,
|
|
4361
|
+
sessionId: sessionId,
|
|
4362
|
+
posthogName: userData.email || userData.name || null // Update posthogName with email
|
|
4363
|
+
};
|
|
4364
|
+
console.log('Sending user data to server:', payload);
|
|
4358
4365
|
const response = yield fetch(`${this.baseUrl}/api/ingestion/user`, {
|
|
4359
4366
|
method: 'POST',
|
|
4360
4367
|
headers: {
|
|
4361
4368
|
'Content-Type': 'application/json',
|
|
4362
4369
|
'Authorization': `Bearer ${this.apiKey}`
|
|
4363
4370
|
},
|
|
4364
|
-
body: JSON.stringify(
|
|
4365
|
-
userId: userId,
|
|
4366
|
-
userAttributes: userData,
|
|
4367
|
-
sessionId: sessionId
|
|
4368
|
-
})
|
|
4371
|
+
body: JSON.stringify(payload)
|
|
4369
4372
|
});
|
|
4370
4373
|
if (!response.ok) {
|
|
4371
4374
|
throw new Error(`Failed to send user data: ${response.statusText} with API key: ${this.apiKey}`);
|
|
4372
4375
|
}
|
|
4373
|
-
|
|
4376
|
+
const result = yield response.json();
|
|
4377
|
+
console.log('Server response:', result);
|
|
4378
|
+
return result;
|
|
4374
4379
|
}
|
|
4375
4380
|
catch (error) {
|
|
4376
4381
|
logError('Error sending user data:', error);
|
|
@@ -5478,35 +5483,29 @@ class HumanBehaviorTracker {
|
|
|
5478
5483
|
logError('Failed to read logs:', e);
|
|
5479
5484
|
}
|
|
5480
5485
|
}
|
|
5486
|
+
/**
|
|
5487
|
+
* Add user identification information to the tracker
|
|
5488
|
+
* If userId is not provided, will use userProperties.email as the userId (if present)
|
|
5489
|
+
*/
|
|
5481
5490
|
addUserInfo(_a) {
|
|
5482
5491
|
return __awaiter$1(this, arguments, void 0, function* ({ userId, userProperties }) {
|
|
5483
5492
|
yield this.ensureInitialized();
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5493
|
+
// Keep the original endUserId (UUID) - don't change it
|
|
5494
|
+
const originalEndUserId = this.endUserId;
|
|
5495
|
+
// Store user properties
|
|
5487
5496
|
this.userProperties = userProperties;
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5497
|
+
// Send user data with the original endUserId
|
|
5498
|
+
yield this.api.sendUserData(originalEndUserId, userProperties, this.sessionId);
|
|
5499
|
+
// Don't update endUserId - keep it as the original UUID
|
|
5500
|
+
// The posthogName will be updated on the server side with the email
|
|
5501
|
+
return originalEndUserId || '';
|
|
5492
5502
|
});
|
|
5493
5503
|
}
|
|
5494
5504
|
/**
|
|
5495
|
-
*
|
|
5496
|
-
* @param authFields Array of field names to check for existing users (e.g., ['email', 'phoneNumber'])
|
|
5505
|
+
* Get current user attributes
|
|
5497
5506
|
*/
|
|
5498
|
-
|
|
5499
|
-
return
|
|
5500
|
-
yield this.ensureInitialized();
|
|
5501
|
-
if (!this.endUserId) {
|
|
5502
|
-
throw new Error('Cannot authenticate before tracker initialization');
|
|
5503
|
-
}
|
|
5504
|
-
const response = yield this.api.sendUserAuth(this.endUserId, { id }, this.sessionId, ["id"]);
|
|
5505
|
-
if (response && response.userId && response.userId !== this.endUserId) {
|
|
5506
|
-
this.endUserId = response.userId;
|
|
5507
|
-
this.setCookie(`human_behavior_end_user_id_${this.apiKey}`, response.userId, 365);
|
|
5508
|
-
}
|
|
5509
|
-
});
|
|
5507
|
+
getUserAttributes() {
|
|
5508
|
+
return Object.assign({}, this.userProperties);
|
|
5510
5509
|
}
|
|
5511
5510
|
start() {
|
|
5512
5511
|
return __awaiter$1(this, void 0, void 0, function* () {
|