Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.

- Allow querying `views_per_visit` with a time dimension in Stats API
- Add `bounce_rate` to page-filtered Top Stats even when imports are included, but render a metric warning about imported data not included in `bounce_rate` tooltip.
- Add `time_on_page` to page-filtered Top Stats even when imports are included, unless legacy time on page is in view.
- Add `time_on_page` to page-filtered Top Stats even when imports are included, unless legacy time on page is in view.
- Adds team_id to query debug metadata (saved in system.query_log log_comment column)
- Add "Unknown" option to Countries shield, for when the country code is unrecognized
- Add "Last 24 Hours" to dashboard time range picker and Stats API v2
Expand All @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.

- Keybind hints are hidden on smaller screens
- Site index is sortable alphanumerically and by traffic
- Use ResizeObserver instead of polling in tracker for scroll depth. Removes forced reflows caused by the tracker script.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion tracker/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"tracker_script_version": 33,
"tracker_script_version": 34,
"type": "module",
"scripts": {
"lint": "eslint",
Expand Down
22 changes: 4 additions & 18 deletions tracker/src/engagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ function getDocumentHeight() {
}

function getCurrentScrollDepthPx() {
var body = document.body || {}
var el = document.documentElement || {}
var viewportHeight = window.innerHeight || el.clientHeight || 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By removing IE support for engagement tracking, these fallbacks are not necessary since window.scrollY and window.innerHeight are well-supported:

https://caniuse.com/mdn-api_window_innerheight
https://caniuse.com/mdn-api_window_scrolly

var scrollTop = window.scrollY || el.scrollTop || body.scrollTop || 0
var viewportHeight = window.innerHeight
var scrollTop = window.scrollY

return currentDocumentHeight <= viewportHeight
? currentDocumentHeight
Expand All @@ -151,23 +149,11 @@ export function init() {
currentDocumentHeight = getDocumentHeight()
maxScrollDepthPx = getCurrentScrollDepthPx()

window.addEventListener('load', function () {
new ResizeObserver(function () {
currentDocumentHeight = getDocumentHeight()

// Update the document height again after every 200ms during the
// next 3 seconds. This makes sure dynamically loaded content is
// also accounted for.
var count = 0
var interval = setInterval(function () {
Copy link
Contributor Author

@ukutaht ukutaht Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to poll the document for height changes during initial load. Any time DOM is loaded and updated, ResizeObserver will keep currentDocumentHeight variable in sync.

currentDocumentHeight = getDocumentHeight()
if (++count === 15) {
clearInterval(interval)
}
}, 200)
})
}).observe(document.documentElement)

document.addEventListener('scroll', function () {
currentDocumentHeight = getDocumentHeight()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to recompute document height on every scroll event. If the document height changes at any point, ResizeObserver will keep it updated.

var currentScrollDepthPx = getCurrentScrollDepthPx()

if (currentScrollDepthPx > maxScrollDepthPx) {
Expand Down
4 changes: 3 additions & 1 deletion tracker/src/plausible.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ function init(overrides) {

initConfig(options)

initEngagementTracking()
if (!COMPILE_COMPAT) {
initEngagementTracking()
}

if (!COMPILE_MANUAL || (COMPILE_CONFIG && config.autoCapturePageviews)) {
initAutocapture(track)
Expand Down
Loading