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/cjs/index.js +25 -18
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +25 -18
- 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 +4 -0
- package/package.json +1 -1
- package/simple-spa.html +184 -4
- package/src/api.ts +13 -6
- package/src/tracker.ts +19 -12
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);
|
|
@@ -5485,21 +5490,23 @@ class HumanBehaviorTracker {
|
|
|
5485
5490
|
addUserInfo(_a) {
|
|
5486
5491
|
return __awaiter$1(this, arguments, void 0, function* ({ userId, userProperties }) {
|
|
5487
5492
|
yield this.ensureInitialized();
|
|
5488
|
-
//
|
|
5489
|
-
const
|
|
5490
|
-
|
|
5491
|
-
return this.endUserId || '';
|
|
5492
|
-
}
|
|
5493
|
+
// Keep the original endUserId (UUID) - don't change it
|
|
5494
|
+
const originalEndUserId = this.endUserId;
|
|
5495
|
+
// Store user properties
|
|
5493
5496
|
this.userProperties = userProperties;
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
}
|
|
5500
|
-
return this.endUserId || '';
|
|
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 || '';
|
|
5501
5502
|
});
|
|
5502
5503
|
}
|
|
5504
|
+
/**
|
|
5505
|
+
* Get current user attributes
|
|
5506
|
+
*/
|
|
5507
|
+
getUserAttributes() {
|
|
5508
|
+
return Object.assign({}, this.userProperties);
|
|
5509
|
+
}
|
|
5503
5510
|
start() {
|
|
5504
5511
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
5505
5512
|
yield this.ensureInitialized();
|