Skip to content

Commit fba8329

Browse files
raifdmuellerclaude
andcommitted
feat(analytics): count anchor opens via card click; close modal on route change
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) <noreply@anthropic.com>
1 parent a941c64 commit fba8329

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

website/src/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ function bindAnchorSelection() {
368368

369369
function handleAnchorSelection(event) {
370370
const { anchorId } = event.detail
371-
getAnchorModalModule().then(({ showAnchorDetails }) => showAnchorDetails(anchorId))
371+
// Navigate to the anchor route instead of opening the modal directly: the
372+
// URL then reflects the open anchor (deep-linkable, Back closes it), and the
373+
// router records it as a pageview so we can see which anchors are opened.
374+
navigate(`/anchor/${anchorId}`)
372375
}
373376

374377
function initCardGridVisualization() {

website/src/utils/router.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ function trackPageview() {
159159
}
160160
}
161161

162+
// Close the anchor modal if it is open. Called when a non-anchor route is
163+
// resolved so the modal doesn't linger over the page after Back/forward or
164+
// in-app navigation. On a non-anchor route closeModal() does not touch the URL.
165+
function closeOpenAnchorModal() {
166+
const modal = typeof document !== 'undefined' ? document.getElementById('anchor-modal') : null
167+
if (modal && !modal.classList.contains('hidden')) {
168+
import('../components/anchor-modal.js').then(({ closeModal }) => closeModal())
169+
}
170+
}
171+
162172
function handleRoute() {
163173
let path = getCurrentRoute()
164174

@@ -202,6 +212,10 @@ function handleRoute() {
202212
return
203213
}
204214

215+
// Leaving an anchor route: close any open anchor modal so Back/forward and
216+
// in-app navigation don't leave it stranded as an overlay over the page.
217+
closeOpenAnchorModal()
218+
205219
const handler = routes.get(path)
206220

207221
if (typeof handler === 'function') {

0 commit comments

Comments
 (0)