Analyse: Verweildauer bei internem Seitenwechsel sofort senden
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ab4c53d6df
commit
30412cb0ea
3 files changed
+83
-3
No files matched your search
Vendored
+18
-1
@@ -214,11 +214,26 @@ function main() {
|
||||
}
|
||||
});
|
||||
const onScroll = safe(function () { maxScroll = Math.max(maxScroll, scrollPct()); });
|
||||
const onLeave = safe(function () {
|
||||
function sendEn() {
|
||||
if (enSent || !allowed()) return;
|
||||
enSent = true;
|
||||
send({ t: 'en', site, path: lastPath || cleanPath(WIN.location.pathname), vp: vp(),
|
||||
sec: Math.max(0, Math.min(3600, Math.round((Date.now() - pvStart) / 1000))), scroll: Math.max(maxScroll, scrollPct()) });
|
||||
}
|
||||
const onLeave = safe(sendEn);
|
||||
// Interner Seitenwechsel per Link: en sofort senden, der Beacon beim pagehide geht in Chromium oft verloren.
|
||||
// Bubbling-Listener am Dokument: laeuft nach den Handlern der Seite, defaultPrevented ist dann bekannt.
|
||||
const onLinkClick = safe(function (e) {
|
||||
if (e.defaultPrevented || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || (typeof e.button === 'number' && e.button !== 0)) return;
|
||||
let a = e.target;
|
||||
while (a && String(a.tagName).toUpperCase() !== 'A') a = a.parentNode;
|
||||
if (!a || hosts.indexOf(e.target) !== -1) return;
|
||||
const tg = String(a.getAttribute('target') || '').toLowerCase();
|
||||
if ((tg && tg !== '_self') || a.getAttribute('download') !== null) return;
|
||||
const u = new URL(String(a.href || a.getAttribute('href') || ''), WIN.location.href);
|
||||
if (u.protocol !== 'http:' && u.protocol !== 'https:') return;
|
||||
if (u.origin !== WIN.location.origin || u.pathname === WIN.location.pathname) return;
|
||||
sendEn();
|
||||
});
|
||||
const onVis = safe(function () { if (DOC.visibilityState === 'hidden') onLeave(); });
|
||||
|
||||
@@ -234,6 +249,7 @@ function main() {
|
||||
if (tracking) return;
|
||||
tracking = true;
|
||||
DOC.addEventListener('click', onClick, { capture: true, passive: true });
|
||||
DOC.addEventListener('click', onLinkClick, { passive: true });
|
||||
DOC.addEventListener('visibilitychange', onVis);
|
||||
WIN.addEventListener('pagehide', onLeave);
|
||||
WIN.addEventListener('scroll', onScroll, { passive: true });
|
||||
@@ -241,6 +257,7 @@ function main() {
|
||||
function stopTracking() {
|
||||
tracking = false;
|
||||
DOC.removeEventListener('click', onClick, { capture: true });
|
||||
DOC.removeEventListener('click', onLinkClick);
|
||||
DOC.removeEventListener('visibilitychange', onVis);
|
||||
WIN.removeEventListener('pagehide', onLeave);
|
||||
WIN.removeEventListener('scroll', onScroll);
|
||||
|
||||
Reference in new issue
Block a user