@zaplier/sdk 1.7.3 β 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/index.cjs +224 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +224 -39
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +224 -39
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/modules/auto-tracker.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -19574,24 +19574,73 @@ class AutoTracker {
|
|
|
19574
19574
|
if (this.config.trackScrolls) {
|
|
19575
19575
|
const scrollHandler = this.createEnhancedScrollHandler();
|
|
19576
19576
|
this.delegationHandlers.set('scroll', scrollHandler);
|
|
19577
|
-
//
|
|
19578
|
-
|
|
19577
|
+
// MAJOR FIX: Use window instead of document for scroll events
|
|
19578
|
+
// Document doesn't reliably receive scroll events in all browsers
|
|
19579
|
+
const scrollTarget = window;
|
|
19580
|
+
const scrollOptions = {
|
|
19581
|
+
passive: false, // Changed from passive: true to ensure handler executes
|
|
19582
|
+
capture: false
|
|
19583
|
+
};
|
|
19584
|
+
scrollTarget.addEventListener('scroll', scrollHandler, scrollOptions);
|
|
19585
|
+
// Also add to document as backup (some scenarios need both)
|
|
19586
|
+
document.addEventListener('scroll', scrollHandler, scrollOptions);
|
|
19579
19587
|
if (this.config.debug) {
|
|
19580
|
-
console.log("[π AutoTracker] Scroll delegation handler added to document");
|
|
19588
|
+
console.log("[π AutoTracker] β
Scroll delegation handler added to BOTH window AND document");
|
|
19589
|
+
console.log("[π AutoTracker] π Event listener details:", {
|
|
19590
|
+
primaryTarget: 'window',
|
|
19591
|
+
backupTarget: 'document',
|
|
19592
|
+
eventType: 'scroll',
|
|
19593
|
+
handlerType: typeof scrollHandler,
|
|
19594
|
+
options: scrollOptions,
|
|
19595
|
+
handlerStored: this.delegationHandlers.has('scroll')
|
|
19596
|
+
});
|
|
19597
|
+
// Enhanced test function with real scroll simulation
|
|
19598
|
+
const testHandler = () => {
|
|
19599
|
+
console.log("[π AutoTracker] π§ͺ MANUAL SCROLL TEST - Handler should trigger");
|
|
19600
|
+
scrollHandler(new Event('scroll'));
|
|
19601
|
+
};
|
|
19602
|
+
const testRealScroll = () => {
|
|
19603
|
+
console.log("[π AutoTracker] π§ͺ TESTING REAL SCROLL EVENT");
|
|
19604
|
+
window.scrollBy(0, 1); // Trigger real scroll
|
|
19605
|
+
setTimeout(() => {
|
|
19606
|
+
window.scrollBy(0, -1); // Scroll back
|
|
19607
|
+
}, 100);
|
|
19608
|
+
};
|
|
19609
|
+
// Expose test functions globally for manual testing
|
|
19610
|
+
if (typeof window !== 'undefined') {
|
|
19611
|
+
window.testScrollHandler = testHandler;
|
|
19612
|
+
window.testRealScroll = testRealScroll;
|
|
19613
|
+
console.log("[π AutoTracker] π§ͺ Manual tests available:");
|
|
19614
|
+
console.log("[π AutoTracker] π§ͺ - window.testScrollHandler() (direct handler test)");
|
|
19615
|
+
console.log("[π AutoTracker] π§ͺ - window.testRealScroll() (real scroll test)");
|
|
19616
|
+
}
|
|
19617
|
+
// Add debug listener to verify scroll events are firing
|
|
19618
|
+
const debugScrollListener = () => {
|
|
19619
|
+
console.log("[π AutoTracker] π DEBUG: Real scroll event detected!");
|
|
19620
|
+
};
|
|
19621
|
+
window.addEventListener('scroll', debugScrollListener, { once: true });
|
|
19622
|
+
console.log("[π AutoTracker] π Debug scroll listener added (will fire once on next scroll)");
|
|
19581
19623
|
// Immediate test of element detection
|
|
19582
19624
|
setTimeout(() => {
|
|
19583
19625
|
const scrollElements = this.getCachedScrollElements();
|
|
19584
|
-
console.log(`[π AutoTracker] Initial scroll elements check: ${scrollElements.length} found`);
|
|
19626
|
+
console.log(`[π AutoTracker] π Initial scroll elements check: ${scrollElements.length} found`);
|
|
19585
19627
|
if (scrollElements.length > 0) {
|
|
19586
19628
|
Array.from(scrollElements).forEach((element, index) => {
|
|
19587
19629
|
console.log(`[π AutoTracker] Element ${index + 1}:`, {
|
|
19588
19630
|
id: element.id || 'no-id',
|
|
19589
19631
|
trackEvent: element.getAttribute('data-track-scroll'),
|
|
19590
19632
|
threshold: element.getAttribute('data-scroll-threshold') || '0.5',
|
|
19591
|
-
tagName: element.tagName
|
|
19633
|
+
tagName: element.tagName,
|
|
19634
|
+
rect: element.getBoundingClientRect(),
|
|
19635
|
+
isVisible: element.getBoundingClientRect().height > 0
|
|
19592
19636
|
});
|
|
19593
19637
|
});
|
|
19594
19638
|
}
|
|
19639
|
+
// Test auto-scroll detection
|
|
19640
|
+
setTimeout(() => {
|
|
19641
|
+
console.log("[π AutoTracker] π§ͺ Auto-testing scroll detection in 1 second...");
|
|
19642
|
+
testRealScroll();
|
|
19643
|
+
}, 1000);
|
|
19595
19644
|
}, 100);
|
|
19596
19645
|
}
|
|
19597
19646
|
}
|
|
@@ -19731,38 +19780,75 @@ class AutoTracker {
|
|
|
19731
19780
|
createEnhancedScrollHandler() {
|
|
19732
19781
|
return () => {
|
|
19733
19782
|
try {
|
|
19734
|
-
if (
|
|
19783
|
+
if (this.config.debug) {
|
|
19784
|
+
console.log(`[π AutoTracker] π SCROLL HANDLER CALLED`, {
|
|
19785
|
+
trackScrolls: this.config.trackScrolls,
|
|
19786
|
+
scrollY: window.scrollY,
|
|
19787
|
+
timestamp: Date.now()
|
|
19788
|
+
});
|
|
19789
|
+
}
|
|
19790
|
+
if (!this.config.trackScrolls) {
|
|
19791
|
+
if (this.config.debug) {
|
|
19792
|
+
console.log(`[π AutoTracker] βοΈ Scroll tracking disabled, skipping`);
|
|
19793
|
+
}
|
|
19735
19794
|
return;
|
|
19795
|
+
}
|
|
19736
19796
|
// Adaptive throttling based on scroll frequency
|
|
19737
19797
|
const now = Date.now();
|
|
19738
19798
|
const timeDelta = now - this.scrollThrottle;
|
|
19739
19799
|
const throttleDelay = this.diagnostics.environment?.isMobile ? 150 : 100;
|
|
19740
|
-
if (
|
|
19800
|
+
if (this.config.debug) {
|
|
19801
|
+
console.log(`[π AutoTracker] β±οΈ Throttle check:`, {
|
|
19802
|
+
timeDelta,
|
|
19803
|
+
throttleDelay,
|
|
19804
|
+
willProcess: timeDelta >= throttleDelay,
|
|
19805
|
+
lastScrollThrottle: this.scrollThrottle
|
|
19806
|
+
});
|
|
19807
|
+
}
|
|
19808
|
+
if (timeDelta < throttleDelay) {
|
|
19809
|
+
if (this.config.debug) {
|
|
19810
|
+
console.log(`[π AutoTracker] βΈοΈ Throttled - skipping (${timeDelta}ms < ${throttleDelay}ms)`);
|
|
19811
|
+
}
|
|
19741
19812
|
return;
|
|
19813
|
+
}
|
|
19742
19814
|
this.scrollThrottle = now;
|
|
19743
19815
|
// Enhanced element finding with caching
|
|
19744
19816
|
const scrollElements = this.getCachedScrollElements();
|
|
19745
19817
|
if (this.config.debug) {
|
|
19746
|
-
console.log(`[π AutoTracker]
|
|
19818
|
+
console.log(`[π AutoTracker] π Processing scroll elements:`, {
|
|
19747
19819
|
scrollElementsFound: scrollElements.length,
|
|
19748
19820
|
scrollY: window.scrollY,
|
|
19821
|
+
windowHeight: window.innerHeight,
|
|
19749
19822
|
throttleDelay,
|
|
19750
19823
|
timeDelta
|
|
19751
19824
|
});
|
|
19752
19825
|
}
|
|
19753
19826
|
// Process elements with enhanced visibility detection
|
|
19754
19827
|
if (scrollElements.length > 0) {
|
|
19755
|
-
|
|
19828
|
+
if (this.config.debug) {
|
|
19829
|
+
console.log(`[π AutoTracker] π― Starting to process ${scrollElements.length} elements`);
|
|
19830
|
+
}
|
|
19831
|
+
scrollElements.forEach((element, index) => {
|
|
19832
|
+
if (this.config.debug) {
|
|
19833
|
+
console.log(`[π AutoTracker] π Processing element ${index + 1}/${scrollElements.length}:`, {
|
|
19834
|
+
elementId: element.id || 'no-id',
|
|
19835
|
+
trackEvent: element.getAttribute('data-track-scroll'),
|
|
19836
|
+
hasTriggered: element.getAttribute('data-scroll-triggered') === 'true'
|
|
19837
|
+
});
|
|
19838
|
+
}
|
|
19756
19839
|
this.processScrollElementEnhanced(element);
|
|
19757
19840
|
});
|
|
19841
|
+
if (this.config.debug) {
|
|
19842
|
+
console.log(`[π AutoTracker] β
Finished processing all ${scrollElements.length} elements`);
|
|
19843
|
+
}
|
|
19758
19844
|
}
|
|
19759
19845
|
else if (this.config.debug) {
|
|
19760
|
-
console.log(`[π AutoTracker] No scroll elements found to process`);
|
|
19846
|
+
console.log(`[π AutoTracker] β οΈ No scroll elements found to process - cache might be empty`);
|
|
19761
19847
|
}
|
|
19762
19848
|
}
|
|
19763
19849
|
catch (error) {
|
|
19764
19850
|
if (this.config.debug) {
|
|
19765
|
-
console.error('[β AutoTracker] Enhanced scroll handler error:', error);
|
|
19851
|
+
console.error('[β AutoTracker] CRITICAL: Enhanced scroll handler error:', error);
|
|
19766
19852
|
}
|
|
19767
19853
|
}
|
|
19768
19854
|
};
|
|
@@ -19826,25 +19912,33 @@ class AutoTracker {
|
|
|
19826
19912
|
return;
|
|
19827
19913
|
}
|
|
19828
19914
|
if (this.config.debug) {
|
|
19829
|
-
|
|
19830
|
-
|
|
19831
|
-
|
|
19832
|
-
|
|
19833
|
-
|
|
19834
|
-
|
|
19915
|
+
const shouldTrigger = visibilityRatio >= threshold;
|
|
19916
|
+
console.log(`[π AutoTracker] π DETAILED visibility check for "${eventName}":`, {
|
|
19917
|
+
elementInfo: {
|
|
19918
|
+
id: element.id || 'no-id',
|
|
19919
|
+
className: element.className || 'no-class',
|
|
19920
|
+
tagName: element.tagName,
|
|
19921
|
+
trackEvent: eventName,
|
|
19922
|
+
threshold: threshold
|
|
19835
19923
|
},
|
|
19836
|
-
|
|
19837
|
-
|
|
19838
|
-
|
|
19924
|
+
positioning: {
|
|
19925
|
+
rect_top: Math.round(rect.top),
|
|
19926
|
+
rect_bottom: Math.round(rect.bottom),
|
|
19927
|
+
rect_height: Math.round(elementHeight),
|
|
19928
|
+
window_height: windowHeight,
|
|
19929
|
+
scroll_y: window.scrollY
|
|
19839
19930
|
},
|
|
19840
|
-
|
|
19841
|
-
visibleTop
|
|
19842
|
-
visibleBottom
|
|
19843
|
-
visibleHeight
|
|
19844
|
-
|
|
19845
|
-
threshold
|
|
19846
|
-
|
|
19847
|
-
|
|
19931
|
+
visibilityCalculation: {
|
|
19932
|
+
step1_visibleTop: `Math.max(${Math.round(rect.top)}, 0) = ${visibleTop}`,
|
|
19933
|
+
step2_visibleBottom: `Math.min(${Math.round(rect.bottom)}, ${windowHeight}) = ${visibleBottom}`,
|
|
19934
|
+
step3_visibleHeight: `Math.max(0, ${visibleBottom} - ${visibleTop}) = ${visibleHeight}`,
|
|
19935
|
+
step4_visibilityRatio: `${visibleHeight} / ${Math.round(elementHeight)} = ${Math.round(visibilityRatio * 1000) / 1000}`,
|
|
19936
|
+
step5_comparison: `${Math.round(visibilityRatio * 1000) / 1000} >= ${threshold} = ${shouldTrigger}`
|
|
19937
|
+
},
|
|
19938
|
+
status: {
|
|
19939
|
+
hasTriggered: hasTriggered,
|
|
19940
|
+
willTrigger: shouldTrigger && !hasTriggered,
|
|
19941
|
+
skipReason: hasTriggered ? 'already_triggered' : (!shouldTrigger ? 'not_visible_enough' : 'none')
|
|
19848
19942
|
}
|
|
19849
19943
|
});
|
|
19850
19944
|
}
|
|
@@ -19960,11 +20054,25 @@ class AutoTracker {
|
|
|
19960
20054
|
*/
|
|
19961
20055
|
stop() {
|
|
19962
20056
|
if (this.config.debug) {
|
|
19963
|
-
console.log('[AutoTracker] Stopping auto tracking and cleaning up...');
|
|
20057
|
+
console.log('[π AutoTracker] Stopping enhanced auto tracking and cleaning up...');
|
|
19964
20058
|
}
|
|
19965
|
-
// Remove delegation handlers
|
|
20059
|
+
// Remove delegation handlers from correct targets
|
|
19966
20060
|
this.delegationHandlers.forEach((handler, eventType) => {
|
|
19967
|
-
|
|
20061
|
+
if (eventType === 'click') {
|
|
20062
|
+
const delegationTarget = this.getOptimalDelegationTarget();
|
|
20063
|
+
delegationTarget.removeEventListener('click', handler);
|
|
20064
|
+
}
|
|
20065
|
+
else if (eventType === 'scroll') {
|
|
20066
|
+
// Remove from both window and document (as we added to both)
|
|
20067
|
+
window.removeEventListener('scroll', handler);
|
|
20068
|
+
document.removeEventListener('scroll', handler);
|
|
20069
|
+
if (this.config.debug) {
|
|
20070
|
+
console.log('[π AutoTracker] Removed scroll listeners from window and document');
|
|
20071
|
+
}
|
|
20072
|
+
}
|
|
20073
|
+
else {
|
|
20074
|
+
document.removeEventListener(eventType, handler);
|
|
20075
|
+
}
|
|
19968
20076
|
});
|
|
19969
20077
|
this.delegationHandlers.clear();
|
|
19970
20078
|
// Disconnect observers
|
|
@@ -19979,6 +20087,9 @@ class AutoTracker {
|
|
|
19979
20087
|
// Clear caches
|
|
19980
20088
|
this.observedElements.clear();
|
|
19981
20089
|
this.isInitialized = false;
|
|
20090
|
+
if (this.config.debug) {
|
|
20091
|
+
console.log('[π AutoTracker] Enhanced cleanup completed');
|
|
20092
|
+
}
|
|
19982
20093
|
}
|
|
19983
20094
|
/**
|
|
19984
20095
|
* Legacy method - now handled by intelligent mutation observer
|
|
@@ -20181,17 +20292,18 @@ class AutoTracker {
|
|
|
20181
20292
|
trackEvent(eventName, metadata) {
|
|
20182
20293
|
const trackingStart = performance.now();
|
|
20183
20294
|
if (this.config.debug) {
|
|
20184
|
-
console.log("[π AutoTracker]
|
|
20295
|
+
console.log("[π AutoTracker] π― TRACK EVENT CALLED:", {
|
|
20185
20296
|
eventName,
|
|
20186
20297
|
metadata,
|
|
20187
|
-
timestamp: new Date().toISOString()
|
|
20298
|
+
timestamp: new Date().toISOString(),
|
|
20299
|
+
stackTrace: new Error().stack?.split('\n').slice(1, 4) // Show call stack
|
|
20188
20300
|
});
|
|
20189
20301
|
}
|
|
20190
20302
|
// Comprehensive validation
|
|
20191
20303
|
const validation = this.validateTrackingCall(eventName, metadata);
|
|
20192
20304
|
if (!validation.isValid) {
|
|
20193
20305
|
if (this.config.debug) {
|
|
20194
|
-
console.error("[β AutoTracker]
|
|
20306
|
+
console.error("[β AutoTracker] π« VALIDATION FAILED:", validation.errors);
|
|
20195
20307
|
}
|
|
20196
20308
|
return;
|
|
20197
20309
|
}
|
|
@@ -20212,12 +20324,29 @@ class AutoTracker {
|
|
|
20212
20324
|
...metadata,
|
|
20213
20325
|
};
|
|
20214
20326
|
if (this.config.debug) {
|
|
20215
|
-
console.log("[π‘ AutoTracker]
|
|
20327
|
+
console.log("[π‘ AutoTracker] π€ SENDING EVENT TO SDK:", {
|
|
20328
|
+
eventName,
|
|
20329
|
+
eventData,
|
|
20330
|
+
sdkInstanceExists: !!this.sdkInstance,
|
|
20331
|
+
trackCustomEventExists: typeof this.sdkInstance?.trackCustomEvent === 'function'
|
|
20332
|
+
});
|
|
20333
|
+
}
|
|
20334
|
+
if (!this.sdkInstance) {
|
|
20335
|
+
if (this.config.debug) {
|
|
20336
|
+
console.error("[β AutoTracker] π« SDK INSTANCE IS NULL - CANNOT SEND EVENT");
|
|
20337
|
+
}
|
|
20338
|
+
return;
|
|
20339
|
+
}
|
|
20340
|
+
if (typeof this.sdkInstance.trackCustomEvent !== 'function') {
|
|
20341
|
+
if (this.config.debug) {
|
|
20342
|
+
console.error("[β AutoTracker] π« trackCustomEvent IS NOT A FUNCTION:", typeof this.sdkInstance.trackCustomEvent);
|
|
20343
|
+
}
|
|
20344
|
+
return;
|
|
20216
20345
|
}
|
|
20217
20346
|
const result = this.sdkInstance.trackCustomEvent(eventName, eventData);
|
|
20218
20347
|
if (this.config.debug) {
|
|
20219
20348
|
const trackingEnd = performance.now();
|
|
20220
|
-
console.log("[β
AutoTracker]
|
|
20349
|
+
console.log("[β
AutoTracker] π EVENT SENT SUCCESSFULLY:", {
|
|
20221
20350
|
eventName,
|
|
20222
20351
|
result,
|
|
20223
20352
|
totalLatency: Math.round((trackingEnd - trackingStart) * 100) / 100 + 'ms'
|
|
@@ -20226,11 +20355,13 @@ class AutoTracker {
|
|
|
20226
20355
|
}
|
|
20227
20356
|
catch (error) {
|
|
20228
20357
|
if (this.config.debug) {
|
|
20229
|
-
console.error("[π₯ AutoTracker]
|
|
20358
|
+
console.error("[π₯ AutoTracker] π CRITICAL TRACKING ERROR:", {
|
|
20230
20359
|
eventName,
|
|
20231
20360
|
error: error instanceof Error ? error.message : error,
|
|
20232
20361
|
stack: error instanceof Error ? error.stack : undefined,
|
|
20233
|
-
metadata
|
|
20362
|
+
metadata,
|
|
20363
|
+
sdkInstance: !!this.sdkInstance,
|
|
20364
|
+
sdkInstanceType: typeof this.sdkInstance
|
|
20234
20365
|
});
|
|
20235
20366
|
}
|
|
20236
20367
|
}
|
|
@@ -20291,6 +20422,50 @@ class AutoTracker {
|
|
|
20291
20422
|
* Get comprehensive diagnostic information for debugging
|
|
20292
20423
|
*/
|
|
20293
20424
|
getDiagnostics() {
|
|
20425
|
+
// Create manual test functions
|
|
20426
|
+
const manualTests = {
|
|
20427
|
+
triggerScrollHandler: () => {
|
|
20428
|
+
if (this.config.debug) {
|
|
20429
|
+
console.log("[π§ͺ AutoTracker] Manual scroll handler trigger");
|
|
20430
|
+
}
|
|
20431
|
+
const handler = this.delegationHandlers.get('scroll');
|
|
20432
|
+
if (handler) {
|
|
20433
|
+
handler(new Event('scroll'));
|
|
20434
|
+
}
|
|
20435
|
+
else {
|
|
20436
|
+
console.error("[β AutoTracker] No scroll handler found");
|
|
20437
|
+
}
|
|
20438
|
+
},
|
|
20439
|
+
forceScrollEvent: (elementSelector) => {
|
|
20440
|
+
const element = document.querySelector(elementSelector);
|
|
20441
|
+
if (!element) {
|
|
20442
|
+
console.error(`[β AutoTracker] Element not found: ${elementSelector}`);
|
|
20443
|
+
return;
|
|
20444
|
+
}
|
|
20445
|
+
const eventName = element.getAttribute('data-track-scroll');
|
|
20446
|
+
if (!eventName) {
|
|
20447
|
+
console.error(`[β AutoTracker] Element has no data-track-scroll: ${elementSelector}`);
|
|
20448
|
+
return;
|
|
20449
|
+
}
|
|
20450
|
+
console.log(`[π§ͺ AutoTracker] Force triggering scroll event: ${eventName}`);
|
|
20451
|
+
// Reset trigger state
|
|
20452
|
+
element.removeAttribute('data-scroll-triggered');
|
|
20453
|
+
// Force trigger
|
|
20454
|
+
this.processScrollElementEnhanced(element);
|
|
20455
|
+
},
|
|
20456
|
+
testTrackEvent: (eventName = 'test_event') => {
|
|
20457
|
+
console.log(`[π§ͺ AutoTracker] Testing trackEvent: ${eventName}`);
|
|
20458
|
+
this.trackEvent(eventName, {
|
|
20459
|
+
type: 'test',
|
|
20460
|
+
source: 'manual_diagnostic',
|
|
20461
|
+
timestamp: Date.now()
|
|
20462
|
+
});
|
|
20463
|
+
}
|
|
20464
|
+
};
|
|
20465
|
+
// Expose tests globally for easy access
|
|
20466
|
+
if (typeof window !== 'undefined') {
|
|
20467
|
+
window.autoTrackerTests = manualTests;
|
|
20468
|
+
}
|
|
20294
20469
|
return {
|
|
20295
20470
|
// Initialization status
|
|
20296
20471
|
initialization: {
|
|
@@ -20332,7 +20507,17 @@ class AutoTracker {
|
|
|
20332
20507
|
// Validation status
|
|
20333
20508
|
validation: this.validateTrackingCall('test', {}),
|
|
20334
20509
|
// Debug recommendations
|
|
20335
|
-
recommendations: this.generateRecommendations()
|
|
20510
|
+
recommendations: this.generateRecommendations(),
|
|
20511
|
+
// Manual testing functions
|
|
20512
|
+
manualTests: {
|
|
20513
|
+
available: true,
|
|
20514
|
+
usage: {
|
|
20515
|
+
triggerScrollHandler: 'window.autoTrackerTests.triggerScrollHandler()',
|
|
20516
|
+
forceScrollEvent: 'window.autoTrackerTests.forceScrollEvent("[data-track-scroll]")',
|
|
20517
|
+
testTrackEvent: 'window.autoTrackerTests.testTrackEvent("my_event")'
|
|
20518
|
+
},
|
|
20519
|
+
description: 'Use these functions in the browser console to manually test the AutoTracker'
|
|
20520
|
+
}
|
|
20336
20521
|
};
|
|
20337
20522
|
}
|
|
20338
20523
|
/**
|