@zaplier/sdk 1.6.7 → 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 +65 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +65 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +65 -18
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/modules/auto-tracker.d.ts +1 -6
- package/dist/src/modules/auto-tracker.d.ts.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
19277
|
-
|
|
19278
|
-
|
|
19279
|
-
|
|
19280
|
-
|
|
19281
|
-
|
|
19282
|
-
|
|
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
|
}
|