Analyse-Skript: bei SPA-Seitenwechseln die Verweildauer der vorigen Seite senden
Router-Links (z. B. React Router auf webklar.com) verhindern den Standard-Klick, dann griff onLinkClick nicht und das en der vorigen Seite ging verloren. Jetzt sendet der Seitenwechsel-Timer zuerst en (nur mit Einwilligung, einmal je Seite) und dann das pv der neuen Seite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
07a4e153bf
commit
dd062b1f15
3 files changed
+28
-3
No files matched your search
Vendored
+4
-1
@@ -220,7 +220,10 @@ function main() {
|
|||||||
if (navTimer || !counting()) return;
|
if (navTimer || !counting()) return;
|
||||||
navTimer = setTimeout(safe(function () {
|
navTimer = setTimeout(safe(function () {
|
||||||
navTimer = null;
|
navTimer = null;
|
||||||
if (counting() && cleanPath(WIN.location.pathname) !== lastPath) sendPv(false);
|
if (!counting() || cleanPath(WIN.location.pathname) === lastPath) return;
|
||||||
|
// SPA-Seitenwechsel (Router mit preventDefault, onLinkClick greift dann nicht): en der vorigen Seite zuerst
|
||||||
|
sendEn();
|
||||||
|
sendPv(false);
|
||||||
}), 300);
|
}), 300);
|
||||||
}
|
}
|
||||||
let hooksOn = false;
|
let hooksOn = false;
|
||||||
|
|||||||
@@ -90,7 +90,10 @@ function main() {
|
|||||||
if (navTimer || !counting()) return;
|
if (navTimer || !counting()) return;
|
||||||
navTimer = setTimeout(safe(function () {
|
navTimer = setTimeout(safe(function () {
|
||||||
navTimer = null;
|
navTimer = null;
|
||||||
if (counting() && cleanPath(WIN.location.pathname) !== lastPath) sendPv(false);
|
if (!counting() || cleanPath(WIN.location.pathname) === lastPath) return;
|
||||||
|
// SPA-Seitenwechsel (Router mit preventDefault, onLinkClick greift dann nicht): en der vorigen Seite zuerst
|
||||||
|
sendEn();
|
||||||
|
sendPv(false);
|
||||||
}), 300);
|
}), 300);
|
||||||
}
|
}
|
||||||
let hooksOn = false;
|
let hooksOn = false;
|
||||||
|
|||||||
@@ -565,7 +565,9 @@ test('w.js: SPA-pv bei akzeptierter Einwilligung; nach Widerruf kein en', () =>
|
|||||||
const h = harness({ stored: { v: 1, a: 'accept', bv: BV, t: 1_700_000_000_000 - 1000 } });
|
const h = harness({ stored: { v: 1, a: 'accept', bv: BV, t: 1_700_000_000_000 - 1000 } });
|
||||||
h.win.location.pathname = '/zwei';
|
h.win.location.pathname = '/zwei';
|
||||||
h.history.pushState(null, '', '/zwei'); h.timers.splice(0).forEach((f) => f());
|
h.history.pushState(null, '', '/zwei'); h.timers.splice(0).forEach((f) => f());
|
||||||
assert.deepEqual(h.sent.map((s) => s.d.path), ['/start', '/zwei']);
|
// en der vorigen Seite vor dem pv der neuen (Router-Links verhindern den Standard-Klick, onLinkClick greift nicht)
|
||||||
|
assert.deepEqual(h.sent.map((s) => `${s.d.t}:${s.d.path}`), ['pv:/start', 'en:/start', 'pv:/zwei']);
|
||||||
|
assert.equal(h.sent[1].d.scroll, 55);
|
||||||
h.ck(target());
|
h.ck(target());
|
||||||
assert.equal(h.sent.at(-1).d.path, '/zwei');
|
assert.equal(h.sent.at(-1).d.path, '/zwei');
|
||||||
h.store['wk-consent'] = JSON.stringify({ v: 1, a: 'reject', bv: BV, t: 1_700_000_000_000 });
|
h.store['wk-consent'] = JSON.stringify({ v: 1, a: 'reject', bv: BV, t: 1_700_000_000_000 });
|
||||||
@@ -688,3 +690,20 @@ test('w.js: unbekannte Variante => Kunden-Fassung', () => {
|
|||||||
const p = findAll(hostEl(h).shadow, (n) => n.tagName === 'P')[0];
|
const p = findAll(hostEl(h).shadow, (n) => n.tagName === 'P')[0];
|
||||||
assert.ok(p.textContent.startsWith(BANNER_TEXT));
|
assert.ok(p.textContent.startsWith(BANNER_TEXT));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('w.js: SPA-Wechsel ohne Einwilligung sendet nur pv, kein en', () => {
|
||||||
|
const h = harness();
|
||||||
|
h.win.location.pathname = '/zwei';
|
||||||
|
h.history.pushState(null, '', '/zwei'); h.timers.splice(0).forEach((f) => f());
|
||||||
|
assert.deepEqual(h.types(), ['pv', 'bn:shown', 'pv']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('w.js: en nach SPA-Wechsel nur einmal je Seite (Link-Klick und Router)', () => {
|
||||||
|
const h = harness({ stored: { v: 1, a: 'accept', bv: BV, t: 1_700_000_000_000 - 1000 } });
|
||||||
|
h.leave();
|
||||||
|
h.win.location.pathname = '/zwei';
|
||||||
|
h.history.pushState(null, '', '/zwei'); h.timers.splice(0).forEach((f) => f());
|
||||||
|
assert.deepEqual(h.sent.map((s) => `${s.d.t}:${s.d.path}`), ['pv:/start', 'en:/start', 'pv:/zwei']);
|
||||||
|
h.leave();
|
||||||
|
assert.deepEqual(h.sent.map((s) => `${s.d.t}:${s.d.path}`).slice(-1), ['en:/zwei']);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user