@devskin/browser-sdk 1.0.24 → 1.0.26

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.
@@ -13867,7 +13867,7 @@ class DevSkinSDK {
13867
13867
  * Initialize the DevSkin SDK
13868
13868
  */
13869
13869
  init(config) {
13870
- var _a, _b, _c, _d;
13870
+ var _a;
13871
13871
  if (this.initialized) {
13872
13872
  console.warn('[DevSkin] SDK already initialized');
13873
13873
  return;
@@ -13903,24 +13903,20 @@ class DevSkinSDK {
13903
13903
  this.networkCollector = new NetworkCollector(this.config, this.transport);
13904
13904
  this.networkCollector.start();
13905
13905
  }
13906
- // Initialize heatmap collector
13907
- // Auto-enable heatmap if session recording is enabled
13908
- const heatmapEnabled = ((_a = this.config.heatmapOptions) === null || _a === void 0 ? void 0 : _a.enabled) || ((_b = this.config.sessionRecording) === null || _b === void 0 ? void 0 : _b.enabled);
13909
- if (heatmapEnabled) {
13910
- // Merge default heatmap config with user config
13911
- const heatmapConfig = Object.assign({ enabled: true, trackClicks: true, trackScroll: true, trackMouseMovement: true, mouseMoveSampling: 0.05 }, this.config.heatmapOptions);
13912
- this.config.heatmapOptions = heatmapConfig;
13913
- this.heatmapCollector = new HeatmapCollector(this.config, this.transport);
13914
- this.heatmapCollector.start();
13915
- // Initialize screenshot collector and capture page
13916
- this.screenshotCollector = new ScreenshotCollector(this.config, this.transport);
13917
- this.screenshotCollector.captureAndSend(this.sessionId, window.location.href);
13918
- if (this.config.debug) {
13919
- console.log('[DevSkin] Heatmap collection enabled', ((_c = this.config.sessionRecording) === null || _c === void 0 ? void 0 : _c.enabled) ? '(auto-enabled with session recording)' : '');
13920
- }
13906
+ // Initialize heatmap collector - SEMPRE habilitado
13907
+ // Merge default heatmap config with user config
13908
+ const heatmapConfig = Object.assign({ enabled: true, trackClicks: true, trackScroll: true, trackMouseMovement: true, mouseMoveSampling: 0.1 }, this.config.heatmapOptions);
13909
+ this.config.heatmapOptions = heatmapConfig;
13910
+ this.heatmapCollector = new HeatmapCollector(this.config, this.transport);
13911
+ this.heatmapCollector.start();
13912
+ // Initialize screenshot collector and capture page
13913
+ this.screenshotCollector = new ScreenshotCollector(this.config, this.transport);
13914
+ this.screenshotCollector.captureAndSend(this.sessionId, window.location.href);
13915
+ if (this.config.debug) {
13916
+ console.log('[DevSkin] Heatmap collection enabled (always on)');
13921
13917
  }
13922
13918
  // Initialize session recording with rrweb
13923
- if ((_d = this.config.sessionRecording) === null || _d === void 0 ? void 0 : _d.enabled) {
13919
+ if ((_a = this.config.sessionRecording) === null || _a === void 0 ? void 0 : _a.enabled) {
13924
13920
  // Use RRWebRecorder for complete DOM recording
13925
13921
  this.rrwebRecorder = new RRWebRecorder(this.sessionId, {
13926
13922
  enabled: true,
@@ -14064,11 +14060,32 @@ class DevSkinSDK {
14064
14060
  * Private methods
14065
14061
  */
14066
14062
  startSession() {
14067
- var _a;
14063
+ var _a, _b, _c;
14064
+ // Check if there's an active session (stored in sessionStorage to persist across page navigations)
14065
+ const existingSessionId = sessionStorage.getItem('devskin_session_id');
14066
+ const existingSessionStart = sessionStorage.getItem('devskin_session_start');
14067
+ if (existingSessionId && existingSessionStart) {
14068
+ // Resume existing session
14069
+ this.sessionId = existingSessionId;
14070
+ this.sessionStartTime = parseInt(existingSessionStart, 10);
14071
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug) {
14072
+ console.log('[DevSkin] Resuming existing session:', this.sessionId);
14073
+ }
14074
+ // Send page view but DON'T create a new session
14075
+ // The session is already created, just continue it
14076
+ return;
14077
+ }
14078
+ // Create new session
14068
14079
  this.sessionId = this.generateId();
14069
14080
  this.sessionStartTime = Date.now();
14081
+ // Store in sessionStorage (persists across page navigations in same tab)
14082
+ sessionStorage.setItem('devskin_session_id', this.sessionId);
14083
+ sessionStorage.setItem('devskin_session_start', this.sessionStartTime.toString());
14070
14084
  const sessionData = Object.assign({ session_id: this.sessionId, user_id: this.userId || undefined, anonymous_id: this.anonymousId, started_at: new Date().toISOString() }, this.getContextData());
14071
- (_a = this.transport) === null || _a === void 0 ? void 0 : _a.startSession(sessionData);
14085
+ (_b = this.transport) === null || _b === void 0 ? void 0 : _b.startSession(sessionData);
14086
+ if ((_c = this.config) === null || _c === void 0 ? void 0 : _c.debug) {
14087
+ console.log('[DevSkin] New session created:', this.sessionId);
14088
+ }
14072
14089
  }
14073
14090
  getContextData() {
14074
14091
  const context = {};
@@ -14105,16 +14122,26 @@ class DevSkinSDK {
14105
14122
  });
14106
14123
  }
14107
14124
  setupUnloadTracking() {
14108
- window.addEventListener('beforeunload', () => {
14125
+ // Use pagehide event which is more reliable than beforeunload
14126
+ window.addEventListener('pagehide', (event) => {
14109
14127
  var _a, _b;
14110
- this.track('page_unload');
14111
- // Send session end update with duration AND context data
14112
- if (this.sessionId && this.sessionStartTime) {
14113
- const endedAt = new Date();
14114
- const durationMs = Date.now() - this.sessionStartTime;
14115
- (_a = this.transport) === null || _a === void 0 ? void 0 : _a.startSession(Object.assign({ session_id: this.sessionId, user_id: this.userId || undefined, anonymous_id: this.anonymousId, ended_at: endedAt.toISOString(), duration_ms: durationMs }, this.getContextData()));
14128
+ // Only end session if tab is actually closing (not just navigating)
14129
+ // persisted = false means the page is going into bfcache (navigation)
14130
+ // persisted = true OR event doesn't exist means actual close
14131
+ const isActualClose = !event.persisted;
14132
+ if (isActualClose) {
14133
+ this.track('page_unload');
14134
+ // Only send session end if tab is actually closing
14135
+ if (this.sessionId && this.sessionStartTime) {
14136
+ const endedAt = new Date();
14137
+ const durationMs = Date.now() - this.sessionStartTime;
14138
+ (_a = this.transport) === null || _a === void 0 ? void 0 : _a.startSession(Object.assign({ session_id: this.sessionId, user_id: this.userId || undefined, anonymous_id: this.anonymousId, ended_at: endedAt.toISOString(), duration_ms: durationMs }, this.getContextData()));
14139
+ // Clear session storage since session is ending
14140
+ sessionStorage.removeItem('devskin_session_id');
14141
+ sessionStorage.removeItem('devskin_session_start');
14142
+ }
14116
14143
  }
14117
- // Send any pending data
14144
+ // Always flush pending data (whether navigation or close)
14118
14145
  (_b = this.transport) === null || _b === void 0 ? void 0 : _b.flush(true); // Use beacon for reliability
14119
14146
  });
14120
14147
  }