humanbehavior-js 0.3.3 → 0.3.5
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 +11 -56
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +12 -56
- 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 +3 -24
- package/package.json +1 -1
- package/src/index.ts +0 -3
- package/src/tracker.ts +13 -4
- package/src/server.ts +0 -63
package/dist/cjs/index.js
CHANGED
|
@@ -5564,6 +5564,10 @@ class HumanBehaviorTracker {
|
|
|
5564
5564
|
emit: (event) => {
|
|
5565
5565
|
// ✅ DIRECT EVENT HANDLING - Let rrweb handle events natively
|
|
5566
5566
|
this.addEvent(event);
|
|
5567
|
+
// ✅ DEBUG FULLSNAPSHOT GENERATION
|
|
5568
|
+
if (event.type === 2) { // FullSnapshot
|
|
5569
|
+
logDebug(`🎯 FullSnapshot generated at ${new Date().toISOString()}`);
|
|
5570
|
+
}
|
|
5567
5571
|
},
|
|
5568
5572
|
inlineStylesheet: true,
|
|
5569
5573
|
recordCanvas: true,
|
|
@@ -5575,6 +5579,9 @@ class HumanBehaviorTracker {
|
|
|
5575
5579
|
// ✅ RRWEB BUILT-IN MASKING - More reliable than custom redaction
|
|
5576
5580
|
maskAllInputs: false, // Let users control this via selectors
|
|
5577
5581
|
maskTextSelector: this.redactionManager.getMaskTextSelector() || undefined,
|
|
5582
|
+
// ✅ FULLSNAPSHOT GENERATION - Use reasonable intervals (PostHog-style)
|
|
5583
|
+
checkoutEveryNms: 300000, // Take FullSnapshot every 5 minutes (like PostHog)
|
|
5584
|
+
checkoutEveryNth: 1000, // Take FullSnapshot every 1000 events
|
|
5578
5585
|
// ✅ SELECTOR-BASED REDACTION - Users control via CSS selectors
|
|
5579
5586
|
// No custom masking functions needed - rrweb handles this natively
|
|
5580
5587
|
});
|
|
@@ -5852,15 +5859,15 @@ class HumanBehaviorTracker {
|
|
|
5852
5859
|
}
|
|
5853
5860
|
/**
|
|
5854
5861
|
* Get current snapshot frequency info
|
|
5855
|
-
* Uses
|
|
5862
|
+
* Uses configured values (5 minutes, 1000 events) - PostHog-style
|
|
5856
5863
|
*/
|
|
5857
5864
|
getSnapshotFrequencyInfo() {
|
|
5858
5865
|
const sessionDuration = Date.now() - this.sessionStartTime;
|
|
5859
5866
|
return {
|
|
5860
5867
|
sessionDuration,
|
|
5861
|
-
currentInterval:
|
|
5862
|
-
currentThreshold:
|
|
5863
|
-
phase: '
|
|
5868
|
+
currentInterval: 300000, // Configured - 5 minutes (PostHog-style)
|
|
5869
|
+
currentThreshold: 1000, // Configured - 1000 events
|
|
5870
|
+
phase: 'configured' // Using explicit configuration
|
|
5864
5871
|
};
|
|
5865
5872
|
}
|
|
5866
5873
|
/**
|
|
@@ -5935,57 +5942,6 @@ if (isBrowser) {
|
|
|
5935
5942
|
window.HumanBehaviorTracker = HumanBehaviorTracker;
|
|
5936
5943
|
}
|
|
5937
5944
|
|
|
5938
|
-
/**
|
|
5939
|
-
* Server-side utilities for HumanBehavior SDK
|
|
5940
|
-
*/
|
|
5941
|
-
/**
|
|
5942
|
-
* Identify user from server-side (NextAuth, Firebase, etc.)
|
|
5943
|
-
* Use this in your auth events to track users immediately on sign-in
|
|
5944
|
-
*/
|
|
5945
|
-
function identifyUser(userId, // Separate userId parameter (should be stable unique identifier)
|
|
5946
|
-
userData, apiKey) {
|
|
5947
|
-
return __awaiter$1(this, void 0, void 0, function* () {
|
|
5948
|
-
try {
|
|
5949
|
-
const response = yield fetch('https://ingest.humanbehavior.co/api/ingestion/user', {
|
|
5950
|
-
method: 'POST',
|
|
5951
|
-
headers: {
|
|
5952
|
-
'Content-Type': 'application/json',
|
|
5953
|
-
'Authorization': `Bearer ${apiKey}`
|
|
5954
|
-
},
|
|
5955
|
-
body: JSON.stringify({
|
|
5956
|
-
userId: userId, // Use stable unique identifier
|
|
5957
|
-
userAttributes: userData, // Email and other data go here
|
|
5958
|
-
sessionId: 'server-side-identification', // Dummy sessionId for server-side requests
|
|
5959
|
-
posthogName: userData.email || userData.name || null // Update posthogName with email
|
|
5960
|
-
})
|
|
5961
|
-
});
|
|
5962
|
-
if (!response.ok) {
|
|
5963
|
-
const errorText = yield response.text();
|
|
5964
|
-
return {
|
|
5965
|
-
success: false,
|
|
5966
|
-
error: `Failed to identify user: ${response.status} ${response.statusText} - ${errorText}`
|
|
5967
|
-
};
|
|
5968
|
-
}
|
|
5969
|
-
const result = yield response.json();
|
|
5970
|
-
// If server found existing user, return the actual userId
|
|
5971
|
-
if (result.actualUserId && result.actualUserId !== userId) {
|
|
5972
|
-
console.log(`🔄 Server found existing user: ${result.actualUserId} (sent: ${userId})`);
|
|
5973
|
-
return {
|
|
5974
|
-
success: true,
|
|
5975
|
-
actualUserId: result.actualUserId
|
|
5976
|
-
};
|
|
5977
|
-
}
|
|
5978
|
-
return { success: true };
|
|
5979
|
-
}
|
|
5980
|
-
catch (error) {
|
|
5981
|
-
return {
|
|
5982
|
-
success: false,
|
|
5983
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
5984
|
-
};
|
|
5985
|
-
}
|
|
5986
|
-
});
|
|
5987
|
-
}
|
|
5988
|
-
|
|
5989
5945
|
/**
|
|
5990
5946
|
* Main entry point for the HumanBehavior SDK
|
|
5991
5947
|
*/
|
|
@@ -5999,7 +5955,6 @@ exports.HumanBehaviorTracker = HumanBehaviorTracker;
|
|
|
5999
5955
|
exports.MAX_CHUNK_SIZE_BYTES = MAX_CHUNK_SIZE_BYTES;
|
|
6000
5956
|
exports.RedactionManager = RedactionManager;
|
|
6001
5957
|
exports.default = HumanBehaviorTracker;
|
|
6002
|
-
exports.identifyUser = identifyUser;
|
|
6003
5958
|
exports.isChunkSizeExceeded = isChunkSizeExceeded;
|
|
6004
5959
|
exports.logDebug = logDebug;
|
|
6005
5960
|
exports.logError = logError;
|