-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report scroll metrics when page is resized #2399
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2399 +/- ##
==========================================
- Coverage 94.01% 93.98% -0.04%
==========================================
Files 219 219
Lines 6299 6317 +18
Branches 1402 1408 +6
==========================================
+ Hits 5922 5937 +15
- Misses 377 380 +3
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackScrollMetrics.ts
Outdated
Show resolved
Hide resolved
5da6559
to
a1479d4
Compare
…etrics-periodically
…etrics-periodically
…etrics-periodically
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackCommonViewMetrics.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.spec.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.spec.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.spec.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.spec.ts
Show resolved
Hide resolved
…etrics-periodically
…etrics-periodically
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.spec.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.spec.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.spec.ts
Outdated
Show resolved
Hide resolved
observable.notify(computeScrollValues()) | ||
} | ||
|
||
if (window.ResizeObserver) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ question: what about IE11? ResizeObserver
is not supported there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For IE11, the fallback solution is to collect data on the scrolling at regular intervals:
browser-sdk/packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts
Lines 121 to 122 in 9ddc001
const id = setInterval(notify, throttleDuration) | |
return () => clearInterval(id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right, so fallback to setInterval for IE 11 🤔
Do you see any pros / cons to have those two implementations rather than just always using setInterval?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- cons:
- we have two different implementations, which can be troublesome
- pros:
- even if we have two implementations, the two still produce the same values, the only difference lies in the frequency with which these values are produced. For IE we're going to produce new values every second, for other browsers, we're going to produce them only when the page is scrolled or resized
- on modern browser, since we produce values less often, we have less changes of causing layout shifts/reflows caused by scroll/viewport calculation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the resize observer approach seems more "polite" than recomputing the values every second, I am wondering if it is not even too agressive for IE 😕
It could worth to double check that it does not degrade performances there.
Did you look into approaches taken by some resize observer polyfills?
In case there is some interesting alternate approach that could be used everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a way to test the SDK on IE?
I can definitely try an approach with a resize observer polyfill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a way to test the SDK on IE?
Yes, with browserstack
Motivation
We currently have an issue in scrollmaps, as you can see in this widget, many users reach a scroll depth of 100% when the page scroll height is way lower than what it should be.
This is because when the user doesn't scroll, the scroll metrics are only reported once: at loading time.
Since loading time can be reached before the page is fully loaded, it means that we collect wrong scroll metrics
This PR aims to fix this issue by decorrelating scroll height reporting from scroll depth reporting.
Changes
ResizeObserver
to report scroll height increaseTesting
Visit this page with the dev version of the sdk enabled and don't scroll. Clear the search, you should notice that the scroll height has increased
I have gone over the contributing documentation.