@zaplier/sdk 1.7.4 โ†’ 1.7.5

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
@@ -19576,27 +19576,52 @@
19576
19576
  if (this.config.trackScrolls) {
19577
19577
  const scrollHandler = this.createEnhancedScrollHandler();
19578
19578
  this.delegationHandlers.set('scroll', scrollHandler);
19579
- // Always use document for scroll events (window doesn't work with removeEventListener)
19580
- document.addEventListener('scroll', scrollHandler, this.getEventOptions('scroll'));
19579
+ // MAJOR FIX: Use window instead of document for scroll events
19580
+ // Document doesn't reliably receive scroll events in all browsers
19581
+ const scrollTarget = window;
19582
+ const scrollOptions = {
19583
+ passive: false, // Changed from passive: true to ensure handler executes
19584
+ capture: false
19585
+ };
19586
+ scrollTarget.addEventListener('scroll', scrollHandler, scrollOptions);
19587
+ // Also add to document as backup (some scenarios need both)
19588
+ document.addEventListener('scroll', scrollHandler, scrollOptions);
19581
19589
  if (this.config.debug) {
19582
- console.log("[๐Ÿ“œ AutoTracker] โœ… Scroll delegation handler added to document");
19590
+ console.log("[๐Ÿ“œ AutoTracker] โœ… Scroll delegation handler added to BOTH window AND document");
19583
19591
  console.log("[๐Ÿ“œ AutoTracker] ๐Ÿ“‹ Event listener details:", {
19584
- target: 'document',
19592
+ primaryTarget: 'window',
19593
+ backupTarget: 'document',
19585
19594
  eventType: 'scroll',
19586
19595
  handlerType: typeof scrollHandler,
19587
- options: this.getEventOptions('scroll'),
19596
+ options: scrollOptions,
19588
19597
  handlerStored: this.delegationHandlers.has('scroll')
19589
19598
  });
19590
- // Test if handler is actually working
19599
+ // Enhanced test function with real scroll simulation
19591
19600
  const testHandler = () => {
19592
19601
  console.log("[๐Ÿ“œ AutoTracker] ๐Ÿงช MANUAL SCROLL TEST - Handler should trigger");
19593
19602
  scrollHandler(new Event('scroll'));
19594
19603
  };
19595
- // Expose test function globally for manual testing
19604
+ const testRealScroll = () => {
19605
+ console.log("[๐Ÿ“œ AutoTracker] ๐Ÿงช TESTING REAL SCROLL EVENT");
19606
+ window.scrollBy(0, 1); // Trigger real scroll
19607
+ setTimeout(() => {
19608
+ window.scrollBy(0, -1); // Scroll back
19609
+ }, 100);
19610
+ };
19611
+ // Expose test functions globally for manual testing
19596
19612
  if (typeof window !== 'undefined') {
19597
19613
  window.testScrollHandler = testHandler;
19598
- console.log("[๐Ÿ“œ AutoTracker] ๐Ÿงช Manual test available: window.testScrollHandler()");
19614
+ window.testRealScroll = testRealScroll;
19615
+ console.log("[๐Ÿ“œ AutoTracker] ๐Ÿงช Manual tests available:");
19616
+ console.log("[๐Ÿ“œ AutoTracker] ๐Ÿงช - window.testScrollHandler() (direct handler test)");
19617
+ console.log("[๐Ÿ“œ AutoTracker] ๐Ÿงช - window.testRealScroll() (real scroll test)");
19599
19618
  }
19619
+ // Add debug listener to verify scroll events are firing
19620
+ const debugScrollListener = () => {
19621
+ console.log("[๐Ÿ“œ AutoTracker] ๐Ÿ” DEBUG: Real scroll event detected!");
19622
+ };
19623
+ window.addEventListener('scroll', debugScrollListener, { once: true });
19624
+ console.log("[๐Ÿ“œ AutoTracker] ๐Ÿ” Debug scroll listener added (will fire once on next scroll)");
19600
19625
  // Immediate test of element detection
19601
19626
  setTimeout(() => {
19602
19627
  const scrollElements = this.getCachedScrollElements();
@@ -19613,16 +19638,11 @@
19613
19638
  });
19614
19639
  });
19615
19640
  }
19616
- // Also test manually trigger one element
19617
- if (scrollElements.length > 0) {
19618
- const firstElement = scrollElements[0];
19619
- if (firstElement) {
19620
- console.log(`[๐Ÿ“œ AutoTracker] ๐Ÿงช Testing manual trigger on first element:`, firstElement.getAttribute('data-track-scroll'));
19621
- setTimeout(() => {
19622
- console.log("[๐Ÿ“œ AutoTracker] ๐Ÿงช Manual trigger test executed");
19623
- }, 500);
19624
- }
19625
- }
19641
+ // Test auto-scroll detection
19642
+ setTimeout(() => {
19643
+ console.log("[๐Ÿ“œ AutoTracker] ๐Ÿงช Auto-testing scroll detection in 1 second...");
19644
+ testRealScroll();
19645
+ }, 1000);
19626
19646
  }, 100);
19627
19647
  }
19628
19648
  }
@@ -20036,11 +20056,25 @@
20036
20056
  */
20037
20057
  stop() {
20038
20058
  if (this.config.debug) {
20039
- console.log('[AutoTracker] Stopping auto tracking and cleaning up...');
20059
+ console.log('[๐Ÿ“œ AutoTracker] Stopping enhanced auto tracking and cleaning up...');
20040
20060
  }
20041
- // Remove delegation handlers
20061
+ // Remove delegation handlers from correct targets
20042
20062
  this.delegationHandlers.forEach((handler, eventType) => {
20043
- document.removeEventListener(eventType, handler);
20063
+ if (eventType === 'click') {
20064
+ const delegationTarget = this.getOptimalDelegationTarget();
20065
+ delegationTarget.removeEventListener('click', handler);
20066
+ }
20067
+ else if (eventType === 'scroll') {
20068
+ // Remove from both window and document (as we added to both)
20069
+ window.removeEventListener('scroll', handler);
20070
+ document.removeEventListener('scroll', handler);
20071
+ if (this.config.debug) {
20072
+ console.log('[๐Ÿ“œ AutoTracker] Removed scroll listeners from window and document');
20073
+ }
20074
+ }
20075
+ else {
20076
+ document.removeEventListener(eventType, handler);
20077
+ }
20044
20078
  });
20045
20079
  this.delegationHandlers.clear();
20046
20080
  // Disconnect observers
@@ -20055,6 +20089,9 @@
20055
20089
  // Clear caches
20056
20090
  this.observedElements.clear();
20057
20091
  this.isInitialized = false;
20092
+ if (this.config.debug) {
20093
+ console.log('[๐Ÿ“œ AutoTracker] Enhanced cleanup completed');
20094
+ }
20058
20095
  }
20059
20096
  /**
20060
20097
  * Legacy method - now handled by intelligent mutation observer