From fba8329e724c2ae8531aea7b88e22ccfc516a007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=7BAI=7Df=20D=2E=20M=C3=BCller?= Date: Tue, 2 Jun 2026 10:29:46 +0200 Subject: [PATCH] feat(analytics): count anchor opens via card click; close modal on route change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clicking an anchor card opened the modal by calling showAnchorDetails directly, without changing the route — so the most common way to open an anchor was never counted (only deep-links and in-modal cross-refs were). Route card clicks through navigate('/anchor/:id') instead: the URL now reflects the open anchor (deep-linkable, shareable) and the router records it as a pageview, giving real per-anchor view counts. Also fixes a latent bug this surfaces: leaving an anchor route (Back/forward or in-app nav) left the modal stranded as an overlay over the page. The router now closes an open anchor modal whenever a non-anchor route resolves; on a non-anchor route closeModal() doesn't touch the URL. Co-Authored-By: Claude Opus 4.8 (1M context) --- website/src/main.js | 5 ++++- website/src/utils/router.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/website/src/main.js b/website/src/main.js index 7cd28c8..a864a17 100644 --- a/website/src/main.js +++ b/website/src/main.js @@ -368,7 +368,10 @@ function bindAnchorSelection() { function handleAnchorSelection(event) { const { anchorId } = event.detail - getAnchorModalModule().then(({ showAnchorDetails }) => showAnchorDetails(anchorId)) + // Navigate to the anchor route instead of opening the modal directly: the + // URL then reflects the open anchor (deep-linkable, Back closes it), and the + // router records it as a pageview so we can see which anchors are opened. + navigate(`/anchor/${anchorId}`) } function initCardGridVisualization() { diff --git a/website/src/utils/router.js b/website/src/utils/router.js index 8c50246..c2b9c35 100644 --- a/website/src/utils/router.js +++ b/website/src/utils/router.js @@ -159,6 +159,16 @@ function trackPageview() { } } +// Close the anchor modal if it is open. Called when a non-anchor route is +// resolved so the modal doesn't linger over the page after Back/forward or +// in-app navigation. On a non-anchor route closeModal() does not touch the URL. +function closeOpenAnchorModal() { + const modal = typeof document !== 'undefined' ? document.getElementById('anchor-modal') : null + if (modal && !modal.classList.contains('hidden')) { + import('../components/anchor-modal.js').then(({ closeModal }) => closeModal()) + } +} + function handleRoute() { let path = getCurrentRoute() @@ -202,6 +212,10 @@ function handleRoute() { return } + // Leaving an anchor route: close any open anchor modal so Back/forward and + // in-app navigation don't leave it stranded as an overlay over the page. + closeOpenAnchorModal() + const handler = routes.get(path) if (typeof handler === 'function') {