feat(analytics): count anchor opens via card click + fix modal back-button#565
Conversation
…ute 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>
|
Caution Review failedPull request was closed or merged during review WalkthroughDer PR verbindet die Anker-Öffnung mit Router-Navigation: ChangesAnker-Routing und Modal-Lifecycle
Sequence DiagramsequenceDiagram
participant User
participant handleAnchorSelection
participant navigate as Router/<br>navigate()
participant handleRoute
participant closeOpenAnchorModal
participant AnchorModal as `#anchor-modal`<br>Element
User->>handleAnchorSelection: Click anchor
handleAnchorSelection->>navigate: navigate(/anchor/:id)
navigate->>handleRoute: Route change
handleRoute->>closeOpenAnchorModal: closeOpenAnchorModal()
closeOpenAnchorModal->>AnchorModal: Element present?
alt Modal visible
closeOpenAnchorModal->>AnchorModal: import anchor-modal.js
closeOpenAnchorModal->>AnchorModal: closeModal()
end
handleRoute->>handleRoute: Process route
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Tools execution failed with the following error: Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sub-anchor links render as <a href="#" data-sub-anchor>, which were also
matched by the AsciiDoc cross-reference handler (a[href^="#"]). Clicking a
sub-anchor therefore fired both its own handler AND a bogus
navigate('/anchor/') with an empty id. Harmless before, but since the
modal now closes when a non-anchor route resolves (#565), handleRoute
normalizes '/anchor/' → '/anchor' (not an anchor route) and closed the
umbrella modal — breaking the "navigate to sub-anchor / show back button"
E2E tests.
Exclude data-sub-anchor links from the cross-reference handler and ignore
empty ids, so sub-anchor clicks only load the sub-anchor and the modal +
back button stay put.
Verified: full E2E suite (35) green locally, incl. the two umbrella tests
that regressed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
document.referrer is fixed for the whole SPA session, so every in-app pageview we send (LLM-Coding#562/LLM-Coding#565) re-credited the entry referrer — e.g. a single visitor arriving from heise and browsing 20 anchors made heise's referrer list show all 20 paths. Report the referrer only on the initial load (handled by count.js); client-side route changes now send an empty referrer via a callback. External referrers are credited to the landing page only, matching the intuitive "where did this visit come from" meaning. Verified with GoatCounter's get_data: with document.referrer = heise, the landing keeps r="https://www.heise.de" while an SPA anchor view yields r="". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Why
Follow-up to #562. Opening an anchor by clicking a card — the most common interaction — was not counted:
handleAnchorSelectioncalledshowAnchorDetails()directly without changing the route, sohandleRoute/pageview tracking never ran. Only deep-links and in-modal cross-references were counted, making the per-anchor stats nearly empty.What
navigate('/anchor/:id'). The URL reflects the open anchor (deep-linkable, shareable, Back closes it) and the router records the pageview → real per-anchor view counts.handleRoutenow closes an open anchor modal whenever a non-anchor route resolves (on a non-anchor routecloseModal()doesn't touch the URL).Privacy unchanged: path only, no query, no PII.
Verification (preview, real card click)
Clicked the first catalog card (
4mat):/Semantic-Anchors/anchor/4mat, modal open{ path: "/Semantic-Anchors/anchor/4mat", title: "4mat — Semantic Anchors" }/Semantic-Anchors/, modal closed (previously stayed open)All 98 unit tests pass; lint + prettier clean.
🤖 Generated with Claude Code
Summary by CodeRabbit