@zaplier/sdk 1.6.6 → 1.6.8

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 CHANGED
@@ -19265,21 +19265,60 @@ class SessionReplayEngine {
19265
19265
  class AutoTracker {
19266
19266
  constructor(sdkInstance, config = {}) {
19267
19267
  this.observedElements = new Set();
19268
- /**
19269
- * Event handlers (bound to this)
19270
- */
19271
- this.handleClick = (event) => {
19272
- const target = event.target;
19273
- if (target.hasAttribute("data-track-click")) ;
19274
- };
19268
+ this.scrollThrottle = 0;
19275
19269
  this.handleScroll = () => {
19276
- // Scroll is handled by element-specific listeners
19277
- };
19278
- this.handleHover = (event) => {
19279
- // Hover is handled by element-specific listeners
19280
- };
19281
- this.handleForm = (event) => {
19282
- // Form is handled by element-specific listeners
19270
+ if (!this.config.trackScrolls)
19271
+ return;
19272
+ // Throttle scroll events for performance
19273
+ const now = Date.now();
19274
+ if (now - this.scrollThrottle < 100)
19275
+ return; // 100ms throttle
19276
+ this.scrollThrottle = now;
19277
+ const scrollElements = document.querySelectorAll('[data-track-scroll]');
19278
+ if (this.config.debug && scrollElements.length > 0) {
19279
+ console.log(`[AutoTracker] Checking ${scrollElements.length} scroll elements`);
19280
+ }
19281
+ scrollElements.forEach((element) => {
19282
+ let hasTriggered = element.getAttribute('data-scroll-triggered') === 'true';
19283
+ if (hasTriggered)
19284
+ return;
19285
+ const threshold = parseFloat(element.getAttribute("data-scroll-threshold") || "0.5");
19286
+ const rect = element.getBoundingClientRect();
19287
+ const elementHeight = rect.height;
19288
+ const visibleHeight = Math.min(rect.bottom, window.innerHeight) - Math.max(rect.top, 0);
19289
+ const visibilityRatio = Math.max(0, visibleHeight) / elementHeight;
19290
+ if (this.config.debug) {
19291
+ console.log(`[AutoTracker] Element check:`, {
19292
+ elementId: element.id || element.className,
19293
+ visibilityRatio: Math.round(visibilityRatio * 100) / 100,
19294
+ threshold,
19295
+ triggered: hasTriggered
19296
+ });
19297
+ }
19298
+ if (visibilityRatio >= threshold) {
19299
+ element.setAttribute('data-scroll-triggered', 'true');
19300
+ const eventName = element.getAttribute("data-track-scroll");
19301
+ if (!eventName)
19302
+ return;
19303
+ const metadata = this.extractMetadata(element);
19304
+ this.trackEvent(eventName, {
19305
+ type: "scroll",
19306
+ element: element.tagName.toLowerCase(),
19307
+ threshold,
19308
+ scrollDepth: window.scrollY,
19309
+ visibilityRatio: Math.round(visibilityRatio * 100) / 100,
19310
+ ...metadata,
19311
+ });
19312
+ if (this.config.debug) {
19313
+ console.log(`[AutoTracker] Scroll tracked: ${eventName}`, {
19314
+ threshold,
19315
+ visibilityRatio,
19316
+ scrollDepth: window.scrollY,
19317
+ ...metadata
19318
+ });
19319
+ }
19320
+ }
19321
+ });
19283
19322
  };
19284
19323
  this.sdkInstance = sdkInstance;
19285
19324
  this.config = {
@@ -19300,7 +19339,14 @@ class AutoTracker {
19300
19339
  if (!this.config.enabled)
19301
19340
  return;
19302
19341
  if (this.config.debug) {
19303
- console.log("[Zaplier AutoTracker] Iniciando auto tracking");
19342
+ console.log("[Zaplier AutoTracker] Iniciando auto tracking", {
19343
+ enabled: this.config.enabled,
19344
+ trackClicks: this.config.trackClicks,
19345
+ trackScrolls: this.config.trackScrolls,
19346
+ trackViews: this.config.trackViews,
19347
+ trackHovers: this.config.trackHovers,
19348
+ trackForms: this.config.trackForms
19349
+ });
19304
19350
  }
19305
19351
  // Observer para novos elementos no DOM
19306
19352
  this.observeDOM();
@@ -19310,15 +19356,16 @@ class AutoTracker {
19310
19356
  if (this.config.trackViews) {
19311
19357
  this.setupViewTracking();
19312
19358
  }
19359
+ // Setup global event listeners
19360
+ if (this.config.trackScrolls) {
19361
+ document.addEventListener("scroll", this.handleScroll, { passive: true });
19362
+ }
19313
19363
  }
19314
19364
  /**
19315
19365
  * Parar auto tracking
19316
19366
  */
19317
19367
  stop() {
19318
- document.removeEventListener("click", this.handleClick);
19319
19368
  document.removeEventListener("scroll", this.handleScroll);
19320
- document.removeEventListener("mouseover", this.handleHover);
19321
- document.removeEventListener("submit", this.handleForm);
19322
19369
  if (this.intersectionObserver) {
19323
19370
  this.intersectionObserver.disconnect();
19324
19371
  }
@@ -19957,7 +20004,7 @@ const DEFAULT_CONFIG = {
19957
20004
  */
19958
20005
  class ZaplierSDK {
19959
20006
  constructor(userConfig) {
19960
- this.version = "1.7.0";
20007
+ this.version = "1.7.1";
19961
20008
  this.isInitialized = false;
19962
20009
  this.eventQueue = [];
19963
20010
  /**
@@ -20389,7 +20436,8 @@ class ZaplierSDK {
20389
20436
  const visitorIdentity = await this.visitorIdentityManager.getOrCreateVisitorIdentity({
20390
20437
  fingerprintHash: result.data.hash,
20391
20438
  stableCoreHash: result.data.stableCoreHash,
20392
- deviceFingerprint: result.data.hash,
20439
+ // CRITICAL: Use stableCoreHash as deviceFingerprint for consistency with backend
20440
+ deviceFingerprint: result.data.stableCoreHash || result.data.hash,
20393
20441
  sessionId: this.sessionId,
20394
20442
  userAgent: navigator.userAgent,
20395
20443
  ipAddress: undefined, // Will be determined server-side