Skip to content

Commit b76130c

Browse files
committed
debug(analytics): add comprehensive logging for scroll tracking
Add detailed console logs to diagnose scroll depth issues: - Setup log with emoji indicators - Per-element observation status (found/not found) - Intersection Observer callback logs (target, ratio) - Event firing confirmation with emoji This will help identify: 1. Is script running at all? 2. Are elements being found? 3. Is Intersection Observer triggering? 4. Are events reaching Umami? User reports no events firing - these logs will show exactly where it breaks.
1 parent d79ece3 commit b76130c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/scripts/track-scroll-depth.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { trackScrollDepth } from "@/utils/analytics";
99

1010
// Track scroll depth milestones using Intersection Observer
1111
function setupScrollDepthTracking() {
12+
console.log("[Scroll Tracking] 🚀 Setting up scroll depth tracking...");
13+
1214
// Define depth milestones with corresponding sections
1315
const depthMarkers = [
1416
{ depth: 25, selector: "#origins", label: "Origins" },
@@ -24,13 +26,22 @@ function setupScrollDepthTracking() {
2426
const observer = new IntersectionObserver(
2527
(entries) => {
2628
entries.forEach((entry) => {
29+
console.log("[Scroll Observer]", {
30+
target: entry.target.id,
31+
isIntersecting: entry.isIntersecting,
32+
intersectionRatio: entry.intersectionRatio,
33+
});
34+
2735
if (entry.isIntersecting) {
2836
// Find which depth marker this element corresponds to
2937
const marker = depthMarkers.find((m) =>
3038
entry.target.matches(m.selector),
3139
);
3240

3341
if (marker && !firedDepths.has(marker.depth)) {
42+
console.log(
43+
`[Scroll Tracking] 🎯 Reached ${marker.depth}% (${marker.label})`,
44+
);
3445
// Track this depth milestone
3546
trackScrollDepth(
3647
"statsbomb-case-study",
@@ -52,12 +63,23 @@ function setupScrollDepthTracking() {
5263
);
5364

5465
// Observe all depth marker elements
66+
let observedCount = 0;
5567
depthMarkers.forEach((marker) => {
5668
const element = document.querySelector(marker.selector);
5769
if (element) {
5870
observer.observe(element);
71+
observedCount++;
72+
console.log(
73+
`[Scroll Tracking] ✅ Observing: ${marker.selector} (${marker.depth}%)`,
74+
);
75+
} else {
76+
console.warn(`[Scroll Tracking] ❌ Not found: ${marker.selector}`);
5977
}
6078
});
79+
80+
console.log(
81+
`[Scroll Tracking] 📊 Total: ${observedCount}/${depthMarkers.length} elements observed`,
82+
);
6183
}
6284

6385
// Run after page load (support View Transitions)

0 commit comments

Comments
 (0)