@zaplier/sdk 1.7.3 β 1.7.4
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 +182 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +182 -34
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +182 -34
- 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
|
@@ -19577,21 +19577,50 @@ class AutoTracker {
|
|
|
19577
19577
|
// Always use document for scroll events (window doesn't work with removeEventListener)
|
|
19578
19578
|
document.addEventListener('scroll', scrollHandler, this.getEventOptions('scroll'));
|
|
19579
19579
|
if (this.config.debug) {
|
|
19580
|
-
console.log("[π AutoTracker] Scroll delegation handler added to document");
|
|
19580
|
+
console.log("[π AutoTracker] β
Scroll delegation handler added to document");
|
|
19581
|
+
console.log("[π AutoTracker] π Event listener details:", {
|
|
19582
|
+
target: 'document',
|
|
19583
|
+
eventType: 'scroll',
|
|
19584
|
+
handlerType: typeof scrollHandler,
|
|
19585
|
+
options: this.getEventOptions('scroll'),
|
|
19586
|
+
handlerStored: this.delegationHandlers.has('scroll')
|
|
19587
|
+
});
|
|
19588
|
+
// Test if handler is actually working
|
|
19589
|
+
const testHandler = () => {
|
|
19590
|
+
console.log("[π AutoTracker] π§ͺ MANUAL SCROLL TEST - Handler should trigger");
|
|
19591
|
+
scrollHandler(new Event('scroll'));
|
|
19592
|
+
};
|
|
19593
|
+
// Expose test function globally for manual testing
|
|
19594
|
+
if (typeof window !== 'undefined') {
|
|
19595
|
+
window.testScrollHandler = testHandler;
|
|
19596
|
+
console.log("[π AutoTracker] π§ͺ Manual test available: window.testScrollHandler()");
|
|
19597
|
+
}
|
|
19581
19598
|
// Immediate test of element detection
|
|
19582
19599
|
setTimeout(() => {
|
|
19583
19600
|
const scrollElements = this.getCachedScrollElements();
|
|
19584
|
-
console.log(`[π AutoTracker] Initial scroll elements check: ${scrollElements.length} found`);
|
|
19601
|
+
console.log(`[π AutoTracker] π Initial scroll elements check: ${scrollElements.length} found`);
|
|
19585
19602
|
if (scrollElements.length > 0) {
|
|
19586
19603
|
Array.from(scrollElements).forEach((element, index) => {
|
|
19587
19604
|
console.log(`[π AutoTracker] Element ${index + 1}:`, {
|
|
19588
19605
|
id: element.id || 'no-id',
|
|
19589
19606
|
trackEvent: element.getAttribute('data-track-scroll'),
|
|
19590
19607
|
threshold: element.getAttribute('data-scroll-threshold') || '0.5',
|
|
19591
|
-
tagName: element.tagName
|
|
19608
|
+
tagName: element.tagName,
|
|
19609
|
+
rect: element.getBoundingClientRect(),
|
|
19610
|
+
isVisible: element.getBoundingClientRect().height > 0
|
|
19592
19611
|
});
|
|
19593
19612
|
});
|
|
19594
19613
|
}
|
|
19614
|
+
// Also test manually trigger one element
|
|
19615
|
+
if (scrollElements.length > 0) {
|
|
19616
|
+
const firstElement = scrollElements[0];
|
|
19617
|
+
if (firstElement) {
|
|
19618
|
+
console.log(`[π AutoTracker] π§ͺ Testing manual trigger on first element:`, firstElement.getAttribute('data-track-scroll'));
|
|
19619
|
+
setTimeout(() => {
|
|
19620
|
+
console.log("[π AutoTracker] π§ͺ Manual trigger test executed");
|
|
19621
|
+
}, 500);
|
|
19622
|
+
}
|
|
19623
|
+
}
|
|
19595
19624
|
}, 100);
|
|
19596
19625
|
}
|
|
19597
19626
|
}
|
|
@@ -19731,38 +19760,75 @@ class AutoTracker {
|
|
|
19731
19760
|
createEnhancedScrollHandler() {
|
|
19732
19761
|
return () => {
|
|
19733
19762
|
try {
|
|
19734
|
-
if (
|
|
19763
|
+
if (this.config.debug) {
|
|
19764
|
+
console.log(`[π AutoTracker] π SCROLL HANDLER CALLED`, {
|
|
19765
|
+
trackScrolls: this.config.trackScrolls,
|
|
19766
|
+
scrollY: window.scrollY,
|
|
19767
|
+
timestamp: Date.now()
|
|
19768
|
+
});
|
|
19769
|
+
}
|
|
19770
|
+
if (!this.config.trackScrolls) {
|
|
19771
|
+
if (this.config.debug) {
|
|
19772
|
+
console.log(`[π AutoTracker] βοΈ Scroll tracking disabled, skipping`);
|
|
19773
|
+
}
|
|
19735
19774
|
return;
|
|
19775
|
+
}
|
|
19736
19776
|
// Adaptive throttling based on scroll frequency
|
|
19737
19777
|
const now = Date.now();
|
|
19738
19778
|
const timeDelta = now - this.scrollThrottle;
|
|
19739
19779
|
const throttleDelay = this.diagnostics.environment?.isMobile ? 150 : 100;
|
|
19740
|
-
if (
|
|
19780
|
+
if (this.config.debug) {
|
|
19781
|
+
console.log(`[π AutoTracker] β±οΈ Throttle check:`, {
|
|
19782
|
+
timeDelta,
|
|
19783
|
+
throttleDelay,
|
|
19784
|
+
willProcess: timeDelta >= throttleDelay,
|
|
19785
|
+
lastScrollThrottle: this.scrollThrottle
|
|
19786
|
+
});
|
|
19787
|
+
}
|
|
19788
|
+
if (timeDelta < throttleDelay) {
|
|
19789
|
+
if (this.config.debug) {
|
|
19790
|
+
console.log(`[π AutoTracker] βΈοΈ Throttled - skipping (${timeDelta}ms < ${throttleDelay}ms)`);
|
|
19791
|
+
}
|
|
19741
19792
|
return;
|
|
19793
|
+
}
|
|
19742
19794
|
this.scrollThrottle = now;
|
|
19743
19795
|
// Enhanced element finding with caching
|
|
19744
19796
|
const scrollElements = this.getCachedScrollElements();
|
|
19745
19797
|
if (this.config.debug) {
|
|
19746
|
-
console.log(`[π AutoTracker]
|
|
19798
|
+
console.log(`[π AutoTracker] π Processing scroll elements:`, {
|
|
19747
19799
|
scrollElementsFound: scrollElements.length,
|
|
19748
19800
|
scrollY: window.scrollY,
|
|
19801
|
+
windowHeight: window.innerHeight,
|
|
19749
19802
|
throttleDelay,
|
|
19750
19803
|
timeDelta
|
|
19751
19804
|
});
|
|
19752
19805
|
}
|
|
19753
19806
|
// Process elements with enhanced visibility detection
|
|
19754
19807
|
if (scrollElements.length > 0) {
|
|
19755
|
-
|
|
19808
|
+
if (this.config.debug) {
|
|
19809
|
+
console.log(`[π AutoTracker] π― Starting to process ${scrollElements.length} elements`);
|
|
19810
|
+
}
|
|
19811
|
+
scrollElements.forEach((element, index) => {
|
|
19812
|
+
if (this.config.debug) {
|
|
19813
|
+
console.log(`[π AutoTracker] π Processing element ${index + 1}/${scrollElements.length}:`, {
|
|
19814
|
+
elementId: element.id || 'no-id',
|
|
19815
|
+
trackEvent: element.getAttribute('data-track-scroll'),
|
|
19816
|
+
hasTriggered: element.getAttribute('data-scroll-triggered') === 'true'
|
|
19817
|
+
});
|
|
19818
|
+
}
|
|
19756
19819
|
this.processScrollElementEnhanced(element);
|
|
19757
19820
|
});
|
|
19821
|
+
if (this.config.debug) {
|
|
19822
|
+
console.log(`[π AutoTracker] β
Finished processing all ${scrollElements.length} elements`);
|
|
19823
|
+
}
|
|
19758
19824
|
}
|
|
19759
19825
|
else if (this.config.debug) {
|
|
19760
|
-
console.log(`[π AutoTracker] No scroll elements found to process`);
|
|
19826
|
+
console.log(`[π AutoTracker] β οΈ No scroll elements found to process - cache might be empty`);
|
|
19761
19827
|
}
|
|
19762
19828
|
}
|
|
19763
19829
|
catch (error) {
|
|
19764
19830
|
if (this.config.debug) {
|
|
19765
|
-
console.error('[β AutoTracker] Enhanced scroll handler error:', error);
|
|
19831
|
+
console.error('[β AutoTracker] CRITICAL: Enhanced scroll handler error:', error);
|
|
19766
19832
|
}
|
|
19767
19833
|
}
|
|
19768
19834
|
};
|
|
@@ -19826,25 +19892,33 @@ class AutoTracker {
|
|
|
19826
19892
|
return;
|
|
19827
19893
|
}
|
|
19828
19894
|
if (this.config.debug) {
|
|
19829
|
-
|
|
19830
|
-
|
|
19831
|
-
|
|
19832
|
-
|
|
19833
|
-
|
|
19834
|
-
|
|
19895
|
+
const shouldTrigger = visibilityRatio >= threshold;
|
|
19896
|
+
console.log(`[π AutoTracker] π DETAILED visibility check for "${eventName}":`, {
|
|
19897
|
+
elementInfo: {
|
|
19898
|
+
id: element.id || 'no-id',
|
|
19899
|
+
className: element.className || 'no-class',
|
|
19900
|
+
tagName: element.tagName,
|
|
19901
|
+
trackEvent: eventName,
|
|
19902
|
+
threshold: threshold
|
|
19903
|
+
},
|
|
19904
|
+
positioning: {
|
|
19905
|
+
rect_top: Math.round(rect.top),
|
|
19906
|
+
rect_bottom: Math.round(rect.bottom),
|
|
19907
|
+
rect_height: Math.round(elementHeight),
|
|
19908
|
+
window_height: windowHeight,
|
|
19909
|
+
scroll_y: window.scrollY
|
|
19835
19910
|
},
|
|
19836
|
-
|
|
19837
|
-
|
|
19838
|
-
|
|
19911
|
+
visibilityCalculation: {
|
|
19912
|
+
step1_visibleTop: `Math.max(${Math.round(rect.top)}, 0) = ${visibleTop}`,
|
|
19913
|
+
step2_visibleBottom: `Math.min(${Math.round(rect.bottom)}, ${windowHeight}) = ${visibleBottom}`,
|
|
19914
|
+
step3_visibleHeight: `Math.max(0, ${visibleBottom} - ${visibleTop}) = ${visibleHeight}`,
|
|
19915
|
+
step4_visibilityRatio: `${visibleHeight} / ${Math.round(elementHeight)} = ${Math.round(visibilityRatio * 1000) / 1000}`,
|
|
19916
|
+
step5_comparison: `${Math.round(visibilityRatio * 1000) / 1000} >= ${threshold} = ${shouldTrigger}`
|
|
19839
19917
|
},
|
|
19840
|
-
|
|
19841
|
-
|
|
19842
|
-
|
|
19843
|
-
|
|
19844
|
-
ratio: Math.round(visibilityRatio * 1000) / 1000,
|
|
19845
|
-
threshold,
|
|
19846
|
-
triggered: hasTriggered,
|
|
19847
|
-
shouldTrigger: visibilityRatio >= threshold
|
|
19918
|
+
status: {
|
|
19919
|
+
hasTriggered: hasTriggered,
|
|
19920
|
+
willTrigger: shouldTrigger && !hasTriggered,
|
|
19921
|
+
skipReason: hasTriggered ? 'already_triggered' : (!shouldTrigger ? 'not_visible_enough' : 'none')
|
|
19848
19922
|
}
|
|
19849
19923
|
});
|
|
19850
19924
|
}
|
|
@@ -20181,17 +20255,18 @@ class AutoTracker {
|
|
|
20181
20255
|
trackEvent(eventName, metadata) {
|
|
20182
20256
|
const trackingStart = performance.now();
|
|
20183
20257
|
if (this.config.debug) {
|
|
20184
|
-
console.log("[π AutoTracker]
|
|
20258
|
+
console.log("[π AutoTracker] π― TRACK EVENT CALLED:", {
|
|
20185
20259
|
eventName,
|
|
20186
20260
|
metadata,
|
|
20187
|
-
timestamp: new Date().toISOString()
|
|
20261
|
+
timestamp: new Date().toISOString(),
|
|
20262
|
+
stackTrace: new Error().stack?.split('\n').slice(1, 4) // Show call stack
|
|
20188
20263
|
});
|
|
20189
20264
|
}
|
|
20190
20265
|
// Comprehensive validation
|
|
20191
20266
|
const validation = this.validateTrackingCall(eventName, metadata);
|
|
20192
20267
|
if (!validation.isValid) {
|
|
20193
20268
|
if (this.config.debug) {
|
|
20194
|
-
console.error("[β AutoTracker]
|
|
20269
|
+
console.error("[β AutoTracker] π« VALIDATION FAILED:", validation.errors);
|
|
20195
20270
|
}
|
|
20196
20271
|
return;
|
|
20197
20272
|
}
|
|
@@ -20212,12 +20287,29 @@ class AutoTracker {
|
|
|
20212
20287
|
...metadata,
|
|
20213
20288
|
};
|
|
20214
20289
|
if (this.config.debug) {
|
|
20215
|
-
console.log("[π‘ AutoTracker]
|
|
20290
|
+
console.log("[π‘ AutoTracker] π€ SENDING EVENT TO SDK:", {
|
|
20291
|
+
eventName,
|
|
20292
|
+
eventData,
|
|
20293
|
+
sdkInstanceExists: !!this.sdkInstance,
|
|
20294
|
+
trackCustomEventExists: typeof this.sdkInstance?.trackCustomEvent === 'function'
|
|
20295
|
+
});
|
|
20296
|
+
}
|
|
20297
|
+
if (!this.sdkInstance) {
|
|
20298
|
+
if (this.config.debug) {
|
|
20299
|
+
console.error("[β AutoTracker] π« SDK INSTANCE IS NULL - CANNOT SEND EVENT");
|
|
20300
|
+
}
|
|
20301
|
+
return;
|
|
20302
|
+
}
|
|
20303
|
+
if (typeof this.sdkInstance.trackCustomEvent !== 'function') {
|
|
20304
|
+
if (this.config.debug) {
|
|
20305
|
+
console.error("[β AutoTracker] π« trackCustomEvent IS NOT A FUNCTION:", typeof this.sdkInstance.trackCustomEvent);
|
|
20306
|
+
}
|
|
20307
|
+
return;
|
|
20216
20308
|
}
|
|
20217
20309
|
const result = this.sdkInstance.trackCustomEvent(eventName, eventData);
|
|
20218
20310
|
if (this.config.debug) {
|
|
20219
20311
|
const trackingEnd = performance.now();
|
|
20220
|
-
console.log("[β
AutoTracker]
|
|
20312
|
+
console.log("[β
AutoTracker] π EVENT SENT SUCCESSFULLY:", {
|
|
20221
20313
|
eventName,
|
|
20222
20314
|
result,
|
|
20223
20315
|
totalLatency: Math.round((trackingEnd - trackingStart) * 100) / 100 + 'ms'
|
|
@@ -20226,11 +20318,13 @@ class AutoTracker {
|
|
|
20226
20318
|
}
|
|
20227
20319
|
catch (error) {
|
|
20228
20320
|
if (this.config.debug) {
|
|
20229
|
-
console.error("[π₯ AutoTracker]
|
|
20321
|
+
console.error("[π₯ AutoTracker] π CRITICAL TRACKING ERROR:", {
|
|
20230
20322
|
eventName,
|
|
20231
20323
|
error: error instanceof Error ? error.message : error,
|
|
20232
20324
|
stack: error instanceof Error ? error.stack : undefined,
|
|
20233
|
-
metadata
|
|
20325
|
+
metadata,
|
|
20326
|
+
sdkInstance: !!this.sdkInstance,
|
|
20327
|
+
sdkInstanceType: typeof this.sdkInstance
|
|
20234
20328
|
});
|
|
20235
20329
|
}
|
|
20236
20330
|
}
|
|
@@ -20291,6 +20385,50 @@ class AutoTracker {
|
|
|
20291
20385
|
* Get comprehensive diagnostic information for debugging
|
|
20292
20386
|
*/
|
|
20293
20387
|
getDiagnostics() {
|
|
20388
|
+
// Create manual test functions
|
|
20389
|
+
const manualTests = {
|
|
20390
|
+
triggerScrollHandler: () => {
|
|
20391
|
+
if (this.config.debug) {
|
|
20392
|
+
console.log("[π§ͺ AutoTracker] Manual scroll handler trigger");
|
|
20393
|
+
}
|
|
20394
|
+
const handler = this.delegationHandlers.get('scroll');
|
|
20395
|
+
if (handler) {
|
|
20396
|
+
handler(new Event('scroll'));
|
|
20397
|
+
}
|
|
20398
|
+
else {
|
|
20399
|
+
console.error("[β AutoTracker] No scroll handler found");
|
|
20400
|
+
}
|
|
20401
|
+
},
|
|
20402
|
+
forceScrollEvent: (elementSelector) => {
|
|
20403
|
+
const element = document.querySelector(elementSelector);
|
|
20404
|
+
if (!element) {
|
|
20405
|
+
console.error(`[β AutoTracker] Element not found: ${elementSelector}`);
|
|
20406
|
+
return;
|
|
20407
|
+
}
|
|
20408
|
+
const eventName = element.getAttribute('data-track-scroll');
|
|
20409
|
+
if (!eventName) {
|
|
20410
|
+
console.error(`[β AutoTracker] Element has no data-track-scroll: ${elementSelector}`);
|
|
20411
|
+
return;
|
|
20412
|
+
}
|
|
20413
|
+
console.log(`[π§ͺ AutoTracker] Force triggering scroll event: ${eventName}`);
|
|
20414
|
+
// Reset trigger state
|
|
20415
|
+
element.removeAttribute('data-scroll-triggered');
|
|
20416
|
+
// Force trigger
|
|
20417
|
+
this.processScrollElementEnhanced(element);
|
|
20418
|
+
},
|
|
20419
|
+
testTrackEvent: (eventName = 'test_event') => {
|
|
20420
|
+
console.log(`[π§ͺ AutoTracker] Testing trackEvent: ${eventName}`);
|
|
20421
|
+
this.trackEvent(eventName, {
|
|
20422
|
+
type: 'test',
|
|
20423
|
+
source: 'manual_diagnostic',
|
|
20424
|
+
timestamp: Date.now()
|
|
20425
|
+
});
|
|
20426
|
+
}
|
|
20427
|
+
};
|
|
20428
|
+
// Expose tests globally for easy access
|
|
20429
|
+
if (typeof window !== 'undefined') {
|
|
20430
|
+
window.autoTrackerTests = manualTests;
|
|
20431
|
+
}
|
|
20294
20432
|
return {
|
|
20295
20433
|
// Initialization status
|
|
20296
20434
|
initialization: {
|
|
@@ -20332,7 +20470,17 @@ class AutoTracker {
|
|
|
20332
20470
|
// Validation status
|
|
20333
20471
|
validation: this.validateTrackingCall('test', {}),
|
|
20334
20472
|
// Debug recommendations
|
|
20335
|
-
recommendations: this.generateRecommendations()
|
|
20473
|
+
recommendations: this.generateRecommendations(),
|
|
20474
|
+
// Manual testing functions
|
|
20475
|
+
manualTests: {
|
|
20476
|
+
available: true,
|
|
20477
|
+
usage: {
|
|
20478
|
+
triggerScrollHandler: 'window.autoTrackerTests.triggerScrollHandler()',
|
|
20479
|
+
forceScrollEvent: 'window.autoTrackerTests.forceScrollEvent("[data-track-scroll]")',
|
|
20480
|
+
testTrackEvent: 'window.autoTrackerTests.testTrackEvent("my_event")'
|
|
20481
|
+
},
|
|
20482
|
+
description: 'Use these functions in the browser console to manually test the AutoTracker'
|
|
20483
|
+
}
|
|
20336
20484
|
};
|
|
20337
20485
|
}
|
|
20338
20486
|
/**
|