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