humanbehavior-js 0.2.6 → 0.2.7
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 +73 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +73 -5
- 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 +12 -0
- package/package.json +1 -1
- package/src/tracker.ts +113 -30
package/dist/cjs/index.js
CHANGED
|
@@ -4960,6 +4960,9 @@ class HumanBehaviorTracker {
|
|
|
4960
4960
|
this.originalReplaceState = null;
|
|
4961
4961
|
this.navigationListeners = [];
|
|
4962
4962
|
this._connectionBlocked = false;
|
|
4963
|
+
this.recordInstance = null;
|
|
4964
|
+
this.frequencyUpdateInterval = null;
|
|
4965
|
+
this.sessionStartTime = Date.now();
|
|
4963
4966
|
if (!apiKey) {
|
|
4964
4967
|
throw new Error('Human Behavior API Key is required');
|
|
4965
4968
|
}
|
|
@@ -5518,8 +5521,33 @@ class HumanBehaviorTracker {
|
|
|
5518
5521
|
}, this.FLUSH_INTERVAL_MS);
|
|
5519
5522
|
// Enable console tracking
|
|
5520
5523
|
this.enableConsoleTracking();
|
|
5521
|
-
//
|
|
5522
|
-
|
|
5524
|
+
// Adaptive snapshot configuration based on session duration
|
|
5525
|
+
const sessionStartTime = Date.now();
|
|
5526
|
+
let snapshotInterval = 5000; // Start with 5 seconds
|
|
5527
|
+
let eventThreshold = 100; // Start with 100 events
|
|
5528
|
+
// Function to update snapshot frequency based on session duration
|
|
5529
|
+
const updateSnapshotFrequency = () => {
|
|
5530
|
+
const sessionDuration = Date.now() - sessionStartTime;
|
|
5531
|
+
const thirtyMinutes = 30 * 60 * 1000;
|
|
5532
|
+
const twoHours = 2 * 60 * 60 * 1000;
|
|
5533
|
+
if (sessionDuration > twoHours) {
|
|
5534
|
+
// After 2 hours, very infrequent snapshots
|
|
5535
|
+
snapshotInterval = 30000; // 30 seconds
|
|
5536
|
+
eventThreshold = 500; // 500 events
|
|
5537
|
+
logDebug('Reduced snapshot frequency: 30s/500 events (2+ hours)');
|
|
5538
|
+
}
|
|
5539
|
+
else if (sessionDuration > thirtyMinutes) {
|
|
5540
|
+
// After 30 minutes, moderate frequency
|
|
5541
|
+
snapshotInterval = 15000; // 15 seconds
|
|
5542
|
+
eventThreshold = 300; // 300 events
|
|
5543
|
+
logDebug('Reduced snapshot frequency: 15s/300 events (30+ minutes)');
|
|
5544
|
+
}
|
|
5545
|
+
// First 30 minutes: 5s/100 events (default)
|
|
5546
|
+
};
|
|
5547
|
+
// Update frequency every 5 minutes
|
|
5548
|
+
const frequencyUpdateInterval = setInterval(updateSnapshotFrequency, 5 * 60 * 1000);
|
|
5549
|
+
// Start recording with adaptive redaction enabled
|
|
5550
|
+
const recordInstance = record({
|
|
5523
5551
|
emit: (event) => {
|
|
5524
5552
|
// Add additional validation for FullSnapshot events
|
|
5525
5553
|
if (event.type === 2) { // FullSnapshot event
|
|
@@ -5546,10 +5574,13 @@ class HumanBehaviorTracker {
|
|
|
5546
5574
|
blockClass: 'rr-block',
|
|
5547
5575
|
ignoreClass: 'rr-ignore',
|
|
5548
5576
|
maskTextClass: 'rr-ignore',
|
|
5549
|
-
//
|
|
5550
|
-
checkoutEveryNms:
|
|
5551
|
-
checkoutEveryNth:
|
|
5577
|
+
// Adaptive configuration
|
|
5578
|
+
checkoutEveryNms: snapshotInterval,
|
|
5579
|
+
checkoutEveryNth: eventThreshold
|
|
5552
5580
|
});
|
|
5581
|
+
// Store the record instance and interval for cleanup
|
|
5582
|
+
this.recordInstance = recordInstance;
|
|
5583
|
+
this.frequencyUpdateInterval = frequencyUpdateInterval;
|
|
5553
5584
|
});
|
|
5554
5585
|
}
|
|
5555
5586
|
stop() {
|
|
@@ -5561,6 +5592,16 @@ class HumanBehaviorTracker {
|
|
|
5561
5592
|
clearInterval(this.flushInterval);
|
|
5562
5593
|
this.flushInterval = null;
|
|
5563
5594
|
}
|
|
5595
|
+
// Cleanup adaptive snapshot intervals
|
|
5596
|
+
if (this.frequencyUpdateInterval) {
|
|
5597
|
+
clearInterval(this.frequencyUpdateInterval);
|
|
5598
|
+
this.frequencyUpdateInterval = null;
|
|
5599
|
+
}
|
|
5600
|
+
// Stop rrweb recording
|
|
5601
|
+
if (this.recordInstance) {
|
|
5602
|
+
this.recordInstance();
|
|
5603
|
+
this.recordInstance = null;
|
|
5604
|
+
}
|
|
5564
5605
|
// Disable console tracking
|
|
5565
5606
|
this.disableConsoleTracking();
|
|
5566
5607
|
// Cleanup navigation tracking
|
|
@@ -5794,6 +5835,33 @@ class HumanBehaviorTracker {
|
|
|
5794
5835
|
getCurrentUrl() {
|
|
5795
5836
|
return this.currentUrl;
|
|
5796
5837
|
}
|
|
5838
|
+
/**
|
|
5839
|
+
* Get current snapshot frequency info
|
|
5840
|
+
*/
|
|
5841
|
+
getSnapshotFrequencyInfo() {
|
|
5842
|
+
const sessionDuration = Date.now() - this.sessionStartTime;
|
|
5843
|
+
const thirtyMinutes = 30 * 60 * 1000;
|
|
5844
|
+
const twoHours = 2 * 60 * 60 * 1000;
|
|
5845
|
+
let phase = 'initial';
|
|
5846
|
+
let interval = 5000;
|
|
5847
|
+
let threshold = 100;
|
|
5848
|
+
if (sessionDuration > twoHours) {
|
|
5849
|
+
phase = 'extended';
|
|
5850
|
+
interval = 30000;
|
|
5851
|
+
threshold = 500;
|
|
5852
|
+
}
|
|
5853
|
+
else if (sessionDuration > thirtyMinutes) {
|
|
5854
|
+
phase = 'moderate';
|
|
5855
|
+
interval = 15000;
|
|
5856
|
+
threshold = 300;
|
|
5857
|
+
}
|
|
5858
|
+
return {
|
|
5859
|
+
sessionDuration,
|
|
5860
|
+
currentInterval: interval,
|
|
5861
|
+
currentThreshold: threshold,
|
|
5862
|
+
phase
|
|
5863
|
+
};
|
|
5864
|
+
}
|
|
5797
5865
|
/**
|
|
5798
5866
|
* Test if the tracker can reach the ingestion server
|
|
5799
5867
|
*/
|