humanbehavior-js 0.4.5 → 0.4.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/angular/index.cjs +53 -7
- package/dist/cjs/angular/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +53 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/react/index.cjs +53 -7
- package/dist/cjs/react/index.cjs.map +1 -1
- package/dist/cjs/remix/index.cjs +53 -7
- package/dist/cjs/remix/index.cjs.map +1 -1
- package/dist/cjs/svelte/index.cjs +53 -7
- package/dist/cjs/svelte/index.cjs.map +1 -1
- package/dist/cjs/vue/index.cjs +53 -7
- package/dist/cjs/vue/index.cjs.map +1 -1
- package/dist/esm/angular/index.js +53 -7
- package/dist/esm/angular/index.js.map +1 -1
- package/dist/esm/index.js +53 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react/index.js +53 -7
- package/dist/esm/react/index.js.map +1 -1
- package/dist/esm/remix/index.js +53 -7
- package/dist/esm/remix/index.js.map +1 -1
- package/dist/esm/svelte/index.js +53 -7
- package/dist/esm/svelte/index.js.map +1 -1
- package/dist/esm/vue/index.js +53 -7
- package/dist/esm/vue/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/types/angular/index.d.ts +7 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/react/index.d.ts +7 -0
- package/dist/types/remix/index.d.ts +7 -0
- package/dist/types/svelte/index.d.ts +7 -0
- package/package.json +1 -1
- package/src/tracker.ts +60 -8
package/dist/cjs/index.cjs
CHANGED
|
@@ -13238,6 +13238,8 @@ class HumanBehaviorTracker {
|
|
|
13238
13238
|
this._connectionBlocked = false;
|
|
13239
13239
|
this.recordInstance = null;
|
|
13240
13240
|
this.sessionStartTime = Date.now();
|
|
13241
|
+
this.rrwebRecord = null;
|
|
13242
|
+
this.fullSnapshotTimeout = null;
|
|
13241
13243
|
if (!apiKey) {
|
|
13242
13244
|
throw new Error('Human Behavior API Key is required');
|
|
13243
13245
|
}
|
|
@@ -13345,6 +13347,8 @@ class HumanBehaviorTracker {
|
|
|
13345
13347
|
this.originalPushState.apply(history, args);
|
|
13346
13348
|
// Track navigation event
|
|
13347
13349
|
this.trackNavigationEvent('pushState', this.previousUrl, this.currentUrl);
|
|
13350
|
+
// Take FullSnapshot on navigation (like PostHog does)
|
|
13351
|
+
this.takeFullSnapshot();
|
|
13348
13352
|
};
|
|
13349
13353
|
// Override replaceState to capture programmatic navigation
|
|
13350
13354
|
history.replaceState = (...args) => {
|
|
@@ -13354,12 +13358,16 @@ class HumanBehaviorTracker {
|
|
|
13354
13358
|
this.originalReplaceState.apply(history, args);
|
|
13355
13359
|
// Track navigation event
|
|
13356
13360
|
this.trackNavigationEvent('replaceState', this.previousUrl, this.currentUrl);
|
|
13361
|
+
// Take FullSnapshot on navigation (like PostHog does)
|
|
13362
|
+
this.takeFullSnapshot();
|
|
13357
13363
|
};
|
|
13358
13364
|
// Listen for popstate events (back/forward navigation)
|
|
13359
13365
|
const popstateListener = () => {
|
|
13360
13366
|
this.previousUrl = this.currentUrl;
|
|
13361
13367
|
this.currentUrl = window.location.href;
|
|
13362
13368
|
this.trackNavigationEvent('popstate', this.previousUrl, this.currentUrl);
|
|
13369
|
+
// Take FullSnapshot on navigation (like PostHog does)
|
|
13370
|
+
this.takeFullSnapshot();
|
|
13363
13371
|
};
|
|
13364
13372
|
window.addEventListener('popstate', popstateListener);
|
|
13365
13373
|
this.navigationListeners.push(() => {
|
|
@@ -13787,13 +13795,14 @@ class HumanBehaviorTracker {
|
|
|
13787
13795
|
this.flushInterval = window.setInterval(() => {
|
|
13788
13796
|
this.flush();
|
|
13789
13797
|
}, this.FLUSH_INTERVAL_MS);
|
|
13790
|
-
//
|
|
13791
|
-
this.enableConsoleTracking();
|
|
13798
|
+
// Disable console tracking to reduce event pollution
|
|
13799
|
+
// this.enableConsoleTracking();
|
|
13792
13800
|
// ✅ DOM READY DETECTION
|
|
13793
13801
|
// Wait for DOM to be ready before starting recording
|
|
13794
13802
|
const startRecording = () => {
|
|
13795
13803
|
logDebug('🎯 DOM ready, starting session recording');
|
|
13796
13804
|
// ✅ HUMANBEHAVIOR RRWEB CONFIGURATION
|
|
13805
|
+
this.rrwebRecord = record;
|
|
13797
13806
|
const recordInstance = record({
|
|
13798
13807
|
emit: (event) => {
|
|
13799
13808
|
// ✅ DIRECT EVENT HANDLING - Let rrweb handle events natively
|
|
@@ -13815,12 +13824,12 @@ class HumanBehaviorTracker {
|
|
|
13815
13824
|
recordCrossOriginIframes: false, // HumanBehavior default
|
|
13816
13825
|
// ✅ CANVAS RECORDING - Disabled to prevent large data URIs
|
|
13817
13826
|
recordCanvas: false, // Disabled to prevent large data URIs
|
|
13818
|
-
// ✅ FULLSNAPSHOT GENERATION -
|
|
13819
|
-
checkoutEveryNms
|
|
13820
|
-
|
|
13827
|
+
// ✅ FULLSNAPSHOT GENERATION - Following PostHog's approach (no periodic snapshots)
|
|
13828
|
+
// PostHog doesn't use checkoutEveryNms or checkoutEveryNth to avoid animation issues
|
|
13829
|
+
// They rely on initial FullSnapshot + navigation-triggered ones only
|
|
13821
13830
|
});
|
|
13822
|
-
// Store the record instance for cleanup
|
|
13823
|
-
this.recordInstance = recordInstance;
|
|
13831
|
+
// Store the record instance for cleanup
|
|
13832
|
+
this.recordInstance = recordInstance || null;
|
|
13824
13833
|
};
|
|
13825
13834
|
// ✅ DOM READY DETECTION
|
|
13826
13835
|
logDebug(`🎯 DOM ready state: ${document.readyState}`);
|
|
@@ -13839,6 +13848,37 @@ class HumanBehaviorTracker {
|
|
|
13839
13848
|
}
|
|
13840
13849
|
});
|
|
13841
13850
|
}
|
|
13851
|
+
/**
|
|
13852
|
+
* Manually trigger a FullSnapshot (for navigation events)
|
|
13853
|
+
* Delays snapshot to avoid capturing mid-animation states
|
|
13854
|
+
*/
|
|
13855
|
+
takeFullSnapshot() {
|
|
13856
|
+
// Clear any existing timeout to avoid multiple snapshots
|
|
13857
|
+
if (this.fullSnapshotTimeout) {
|
|
13858
|
+
clearTimeout(this.fullSnapshotTimeout);
|
|
13859
|
+
}
|
|
13860
|
+
// Delay FullSnapshot to let animations settle
|
|
13861
|
+
this.fullSnapshotTimeout = window.setTimeout(() => {
|
|
13862
|
+
try {
|
|
13863
|
+
// Wait for any pending animations/transitions to complete
|
|
13864
|
+
requestAnimationFrame(() => {
|
|
13865
|
+
requestAnimationFrame(() => {
|
|
13866
|
+
// Access takeFullSnapshot from the rrweb record function
|
|
13867
|
+
if (this.rrwebRecord && typeof this.rrwebRecord.takeFullSnapshot === 'function') {
|
|
13868
|
+
this.rrwebRecord.takeFullSnapshot();
|
|
13869
|
+
logDebug('✅ FullSnapshot taken for navigation (delayed for animations)');
|
|
13870
|
+
}
|
|
13871
|
+
else {
|
|
13872
|
+
logWarn('⚠️ takeFullSnapshot not available on record function');
|
|
13873
|
+
}
|
|
13874
|
+
});
|
|
13875
|
+
});
|
|
13876
|
+
}
|
|
13877
|
+
catch (error) {
|
|
13878
|
+
logError('❌ Failed to take FullSnapshot for navigation:', error);
|
|
13879
|
+
}
|
|
13880
|
+
}, 1000); // Wait 1 second for animations to settle
|
|
13881
|
+
}
|
|
13842
13882
|
stop() {
|
|
13843
13883
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13844
13884
|
yield this.ensureInitialized();
|
|
@@ -13853,6 +13893,12 @@ class HumanBehaviorTracker {
|
|
|
13853
13893
|
this.recordInstance();
|
|
13854
13894
|
this.recordInstance = null;
|
|
13855
13895
|
}
|
|
13896
|
+
// Clear any pending FullSnapshot timeouts
|
|
13897
|
+
if (this.fullSnapshotTimeout) {
|
|
13898
|
+
clearTimeout(this.fullSnapshotTimeout);
|
|
13899
|
+
this.fullSnapshotTimeout = null;
|
|
13900
|
+
}
|
|
13901
|
+
this.rrwebRecord = null;
|
|
13856
13902
|
// Disable console tracking
|
|
13857
13903
|
this.disableConsoleTracking();
|
|
13858
13904
|
// Cleanup navigation tracking
|