From c47f6df12d93047684a7da4b66cf3553300fdd84 Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Tue, 25 Aug 2026 23:21:03 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=F0=9F=94=A7=EF=BC=9Aupdate=20the?= =?UTF-8?q?=20vendored=20analytics=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The copy here was taken in 2024 and upstream has moved six times since. It is replaced with what `gc.zgo.at/count.js` serves today, which is byte for byte what the project has at 478f026eb9deacb9378a46b96db72e11e9f20557. One of those six matters beyond the byte count. Upstream removed the sizes table, and the script now sends the screen width alone; the copy here still sent the height and the pixel ratio with every visit, to a server with nowhere left to put them. Measured on a phone viewport, `s` went from `390,844,3` to `390`. The rest: `navigator.sendBeacon` is checked before it is called rather than assumed, two compatibility shims for versions long gone are out, a warning reads better, and a per-hit way to skip a session arrived. The file stays byte for byte upstream's, with no local edits, so telling whether it has drifted is one `diff` away. Signed-off-by: Derek Lewis Assisted-by: Claude-Code:claude-opus-5 Refs: https://github.com/OpenINF/openinf.github.io/issues/1548 --- _assets/js/vendor/count.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/_assets/js/vendor/count.js b/_assets/js/vendor/count.js index a1efb328b..3b5f6bc87 100644 --- a/_assets/js/vendor/count.js +++ b/_assets/js/vendor/count.js @@ -3,10 +3,7 @@ ;(function() { 'use strict'; - if (window.goatcounter && window.goatcounter.vars) // Compatibility with very old version; do not use. - window.goatcounter = window.goatcounter.vars - else - window.goatcounter = window.goatcounter || {} + window.goatcounter = window.goatcounter || {} // Load settings from data-goatcounter-settings. var s = document.querySelector('script[data-goatcounter]') @@ -21,13 +18,14 @@ var enc = encodeURIComponent // Get all data we're going to send off to the counter endpoint. - var get_data = function(vars) { + window.goatcounter.get_data = function(vars) { + vars = vars || {} var data = { p: (vars.path === undefined ? goatcounter.path : vars.path), r: (vars.referrer === undefined ? goatcounter.referrer : vars.referrer), t: (vars.title === undefined ? goatcounter.title : vars.title), e: !!(vars.event || goatcounter.event), - s: [window.screen.width, window.screen.height, (window.devicePixelRatio || 1)], + s: window.screen.width, b: is_bot(), q: location.search, } @@ -40,6 +38,7 @@ if (is_empty(data.r)) data.r = document.referrer if (is_empty(data.t)) data.t = document.title if (is_empty(data.p)) data.p = get_path() + if (vars.no_session) data.ns = (typeof(vars.no_session) === 'function' ? vars.no_session(false) : vars.no_session) if (rcb) data.r = rcb(data.r) if (tcb) data.t = tcb(data.t) @@ -84,9 +83,7 @@ // Get the endpoint to send requests to. var get_endpoint = function() { var s = document.querySelector('script[data-goatcounter]') - if (s && s.dataset.goatcounter) - return s.dataset.goatcounter - return (goatcounter.endpoint || window.counter) // counter is for compat; don't use. + return (s && s.dataset.goatcounter) ? s.dataset.goatcounter : goatcounter.endpoint } // Get current path. @@ -111,7 +108,7 @@ } // Filter some requests that we (probably) don't want to count. - goatcounter.filter = function() { + window.goatcounter.filter = function() { if ('visibilityState' in document && document.visibilityState === 'prerender') return 'visibilityState' if (!goatcounter.allow_frame && location !== parent.location) @@ -127,7 +124,7 @@ // Get URL to send to GoatCounter. window.goatcounter.url = function(vars) { - var data = get_data(vars || {}) + var data = window.goatcounter.get_data(vars || {}) if (data.p === null) // null from user callback. return data.rnd = Math.random().toString(36).substr(2, 5) // Browsers don't always listen to Cache-Control. @@ -148,7 +145,7 @@ if (!url) return warn('not counting because path callback returned null') - if (!navigator.sendBeacon(url)) { + if (!navigator || !navigator.sendBeacon || !navigator.sendBeacon(url)) { // This mostly fails due to being blocked by CSP; try again with an // image-based fallback. var img = document.createElement('img') @@ -183,10 +180,11 @@ var send = function(elem) { return function() { goatcounter.count({ - event: true, - path: (elem.dataset.goatcounterClick || elem.name || elem.id || ''), - title: (elem.dataset.goatcounterTitle || elem.title || (elem.innerHTML || '').substr(0, 200) || ''), - referrer: (elem.dataset.goatcounterReferrer || elem.dataset.goatcounterReferral || ''), + event: true, + path: (elem.dataset.goatcounterClick || elem.name || elem.id || ''), + title: (elem.dataset.goatcounterTitle || elem.title || (elem.innerHTML || '').substr(0, 200) || ''), + referrer: (elem.dataset.goatcounterReferrer || elem.dataset.goatcounterReferral || ''), + no_session: ['1', 't', 'true'].indexOf((elem.dataset.goatcounterNoSession || '').toLowerCase()) !== -1, }) } } @@ -231,7 +229,7 @@ var p = document.querySelector(opt.append) if (!p) - return warn('visit_count: append not found: ' + opt.append) + return warn('visit_count: element to append to not found: ' + opt.append) p.appendChild(d) }) } @@ -268,4 +266,4 @@ if (!goatcounter.no_events) goatcounter.bind_events() }) -})(); \ No newline at end of file +})();