Skip to content

Conversation

Copy link

Copilot AI commented Jan 30, 2026

Addressed two edge cases identified in code review for the scroll depth tracking implementation:

Division by zero protection

  • Added check for docHeight <= 0 to handle pages where content fits within viewport
  • Returns 100% scroll instead of NaN/Infinity

Memory leak cleanup

  • Remove scroll event listener once all thresholds (25%, 50%, 75%, 100%) are tracked
  • Prevents unnecessary handler invocations after tracking is complete
const scrollPercent =
  docHeight <= 0 ? 100 : Math.round((scrollTop / docHeight) * 100)

// Remove listener once all thresholds have been tracked
if (firedThresholds.size === scrollThresholds.length) {
  window.removeEventListener('scroll', handleScroll)
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI mentioned this pull request Jan 30, 2026
4 tasks
Copilot AI changed the title [WIP] Add comprehensive GA4 custom event tracking for analytics fix: address review comments for analytics tracking Jan 30, 2026
Copilot AI requested a review from lmammino January 30, 2026 11:59
@lmammino
Copy link
Member

Already being addressed in #30

@lmammino lmammino closed this Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants