@zaplier/sdk 1.7.7 → 1.7.9
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/index.cjs +77 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +77 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +77 -1
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/sdk.d.ts +4 -0
- package/dist/src/sdk.d.ts.map +1 -1
- package/dist/src/utils/session-utils.d.ts +24 -0
- package/dist/src/utils/session-utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21517,6 +21517,52 @@ class ZaplierSDK {
|
|
|
21517
21517
|
const tempVisitorId = this.visitorId || 'temp-' + Date.now().toString(36);
|
|
21518
21518
|
return generateCurrentSessionId(tempVisitorId);
|
|
21519
21519
|
}
|
|
21520
|
+
/**
|
|
21521
|
+
* Update tracking engines with new session ID to maintain consistency
|
|
21522
|
+
*/
|
|
21523
|
+
updateTrackingEnginesSessionId(newSessionId) {
|
|
21524
|
+
try {
|
|
21525
|
+
// Update replay engine session ID if it exists and is recording
|
|
21526
|
+
if (this.replayEngine && this.replayEngine.isRecording()) {
|
|
21527
|
+
if (this.config.debug) {
|
|
21528
|
+
console.log("[Zaplier] Updating replay engine session ID:", newSessionId);
|
|
21529
|
+
}
|
|
21530
|
+
// Stop current recording and restart with new session ID
|
|
21531
|
+
this.replayEngine.stop();
|
|
21532
|
+
this.replayEngine = new SessionReplayEngine(newSessionId, this.backendVisitorId || 'unknown', {
|
|
21533
|
+
sampleRate: 1.0, // Keep recording active
|
|
21534
|
+
inactivityTimeout: 30000,
|
|
21535
|
+
pauseOnInactive: true,
|
|
21536
|
+
});
|
|
21537
|
+
this.replayEngine.setSDKInstance(this);
|
|
21538
|
+
this.replayEngine.start();
|
|
21539
|
+
}
|
|
21540
|
+
// Update heatmap engine session ID if it exists and is recording
|
|
21541
|
+
if (this.heatmapEngine && this.heatmapEngine.isRecording()) {
|
|
21542
|
+
if (this.config.debug) {
|
|
21543
|
+
console.log("[Zaplier] Updating heatmap engine session ID:", newSessionId);
|
|
21544
|
+
}
|
|
21545
|
+
// Stop current recording and restart with new session ID
|
|
21546
|
+
this.heatmapEngine.stop();
|
|
21547
|
+
this.heatmapEngine = new HeatmapEngine(newSessionId, {
|
|
21548
|
+
trackClicks: true,
|
|
21549
|
+
trackScrollDepth: true,
|
|
21550
|
+
trackRageClicks: true,
|
|
21551
|
+
trackMouseMoves: false,
|
|
21552
|
+
});
|
|
21553
|
+
if (this.antiAdblockManager) {
|
|
21554
|
+
this.heatmapEngine.setAntiAdblockManager(this.antiAdblockManager);
|
|
21555
|
+
}
|
|
21556
|
+
this.heatmapEngine.start();
|
|
21557
|
+
}
|
|
21558
|
+
if (this.config.debug) {
|
|
21559
|
+
console.log("[Zaplier] Tracking engines updated with session ID:", newSessionId);
|
|
21560
|
+
}
|
|
21561
|
+
}
|
|
21562
|
+
catch (error) {
|
|
21563
|
+
console.error("[Zaplier] Failed to update tracking engines session ID:", error);
|
|
21564
|
+
}
|
|
21565
|
+
}
|
|
21520
21566
|
/**
|
|
21521
21567
|
* Initialize Anti-Adblock Manager
|
|
21522
21568
|
*/
|
|
@@ -21837,12 +21883,25 @@ class ZaplierSDK {
|
|
|
21837
21883
|
console.log("[Zaplier] Backend visitor ID received and processed:", response.visitorId);
|
|
21838
21884
|
}
|
|
21839
21885
|
}
|
|
21840
|
-
if
|
|
21886
|
+
// CRITICAL: Only update session ID if we don't have one yet or if it's temporary
|
|
21887
|
+
// Once a session ID is established and tracking engines are started, keep it consistent
|
|
21888
|
+
// to prevent replay/event session ID mismatches
|
|
21889
|
+
if (response.sessionId && (!this.sessionId || this.sessionId.includes('temp-'))) {
|
|
21890
|
+
const oldSessionId = this.sessionId;
|
|
21841
21891
|
this.sessionId = response.sessionId;
|
|
21892
|
+
// Update tracking engines with new session ID if they exist
|
|
21893
|
+
if (oldSessionId !== this.sessionId && this.sessionId) {
|
|
21894
|
+
this.updateTrackingEnginesSessionId(this.sessionId);
|
|
21895
|
+
}
|
|
21842
21896
|
}
|
|
21843
21897
|
else if (this.backendVisitorId && (!this.sessionId || this.sessionId.includes('temp-'))) {
|
|
21844
21898
|
// Generate new session ID now that we have the proper visitor ID
|
|
21899
|
+
const oldSessionId = this.sessionId;
|
|
21845
21900
|
this.sessionId = generateCurrentSessionId(this.backendVisitorId);
|
|
21901
|
+
// Update tracking engines with new session ID if they exist
|
|
21902
|
+
if (oldSessionId !== this.sessionId && this.sessionId) {
|
|
21903
|
+
this.updateTrackingEnginesSessionId(this.sessionId);
|
|
21904
|
+
}
|
|
21846
21905
|
}
|
|
21847
21906
|
return response;
|
|
21848
21907
|
}
|
|
@@ -21888,6 +21947,23 @@ class ZaplierSDK {
|
|
|
21888
21947
|
if (this.config.debug) {
|
|
21889
21948
|
console.log("[Zaplier] Replay batch result:", result);
|
|
21890
21949
|
}
|
|
21950
|
+
// CRITICAL: Synchronize session ID if backend returned a normalized one
|
|
21951
|
+
// This ensures all tracking components use the same session ID
|
|
21952
|
+
if (result.sessionId && result.sessionId !== this.sessionId) {
|
|
21953
|
+
const oldSessionId = this.sessionId;
|
|
21954
|
+
this.sessionId = result.sessionId;
|
|
21955
|
+
if (this.config.debug) {
|
|
21956
|
+
console.log("[Zaplier] Session ID synchronized from replay response:", {
|
|
21957
|
+
oldSessionId,
|
|
21958
|
+
newSessionId: this.sessionId,
|
|
21959
|
+
originalSessionId: result.originalSessionId
|
|
21960
|
+
});
|
|
21961
|
+
}
|
|
21962
|
+
// Update all tracking engines with the normalized session ID
|
|
21963
|
+
if (oldSessionId !== this.sessionId && this.sessionId) {
|
|
21964
|
+
this.updateTrackingEnginesSessionId(this.sessionId);
|
|
21965
|
+
}
|
|
21966
|
+
}
|
|
21891
21967
|
return result;
|
|
21892
21968
|
}
|
|
21893
21969
|
catch (error) {
|