Skip to content

Commit 633c25e

Browse files
committed
debug(analytics): add console logs to scroll depth tracking
Add debug logging to diagnose why scroll events aren't firing: - Log when setup runs - Log each element being observed (or warn if not found) - Log total observed elements count - Log when each depth milestone is reached This will help identify if: 1. Script is loading at all 2. Elements are being found (#origins, #architecture, etc.) 3. Intersection Observer is triggering 4. Events are being fired but not tracked Check browser console on production after deployment.
1 parent 851365c commit 633c25e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/scripts/track-scroll-depth.ts

Lines changed: 16 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" },
@@ -31,6 +33,9 @@ function setupScrollDepthTracking() {
3133
);
3234

3335
if (marker && !firedDepths.has(marker.depth)) {
36+
console.log(
37+
`[Scroll Tracking] Reached ${marker.depth}% (${marker.label})`,
38+
);
3439
// Track this depth milestone
3540
trackScrollDepth(
3641
"statsbomb-case-study",
@@ -52,12 +57,23 @@ function setupScrollDepthTracking() {
5257
);
5358

5459
// Observe all depth marker elements
60+
let observedCount = 0;
5561
depthMarkers.forEach((marker) => {
5662
const element = document.querySelector(marker.selector);
5763
if (element) {
5864
observer.observe(element);
65+
observedCount++;
66+
console.log(
67+
`[Scroll Tracking] Observing: ${marker.selector} (${marker.depth}%)`,
68+
);
69+
} else {
70+
console.warn(`[Scroll Tracking] Element not found: ${marker.selector}`);
5971
}
6072
});
73+
74+
console.log(
75+
`[Scroll Tracking] Observing ${observedCount}/${depthMarkers.length} elements`,
76+
);
6177
}
6278

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

0 commit comments

Comments
 (0)