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