close
Skip to content

Fix search-funnel analytics: report to Matomo via _paq + sendBeacon - #13038

Merged
cdrini merged 3 commits into
internetarchive:masterfrom
lokesh:fix-search-tracking
Jun 25, 2026
Merged

Fix search-funnel analytics: report to Matomo via _paq + sendBeacon#13038
cdrini merged 3 commits into
internetarchive:masterfrom
lokesh:fix-search-tracking

Conversation

@lokesh

@lokesh lokesh commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Closes #13020

fix — The search-funnel events added in #12948 emitted but never landed in Matomo.

They were sent through archive_analytics.ol_send_event_ping, which pings Athena — and Athena doesn't forward events into Matomo (confirmed by @scottbarnes on #13020). Matomo normally ingests OL events via a tag-manager DOM trigger on data-ol-link-track, but that trigger can't see inside Shadow DOM, where the Lit search modal and ol-toggle live. So these controls had no path into Matomo.

Technical

  • New trackEvent(category, action, label) helper in ol.analytics.js pushes onto Matomo's _paq queue directly — the same path the DOM trigger uses, so events report regardless of Shadow DOM. SearchModal._track() and the SearchFilterBar toggle route through it; the Athena ping is dropped.
  • head.html now pushes ['alwaysUseSendBeacon'], so events that fire right before a navigation (result-click, "see all", toggle) are sent via navigator.sendBeacon() and survive the page unload.

Testing

With a Matomo-enabled environment, spy on the queue in DevTools: const o = _paq.push.bind(_paq); _paq.push = (...a) => { console.log('PAQ', ...a); return o(...a); };

  1. Open the search modal → ['trackEvent', 'SearchModal', 'Open', 'click'].
  2. Type a query, click a result → ResultClick / edition:3; "See all" → SeeAllResults / hasResults; no-results query → NoResults.
  3. On /search, toggle Readable Only → SearchFilter / AvailabilityOn|Off.
  4. Admin-side (@cdrini, per the issue): confirm these appear under Behaviour → Events.

Screenshot

No UI changes — analytics wiring only.

Stakeholders

@cdrini (Matomo admin; suggested the _paq approach on the issue)

…eacon

The search-modal and availability-toggle events added in internetarchive#12948 only ever
reached Athena (via ol_send_event_ping), which does not forward into Matomo,
so they never reported. Matomo normally ingests these via a tag-manager DOM
trigger on data-ol-link-track, but that trigger can't see Shadow DOM (the Lit
search modal / ol-toggle).

Add a trackEvent() helper that pushes straight onto Matomo's _paq queue — the
path the trigger ultimately uses — and route SearchModal._track and the
SearchFilterBar toggle through it. Enable alwaysUseSendBeacon so events fired
right before a navigation survive the page unload.
@lokesh
lokesh requested a review from cdrini June 24, 2026 22:42
@lokesh lokesh added the Needs: Review This issue/PR needs to be reviewed in order to be closed or merged (see comments). [managed] label Jun 24, 2026

@cdrini cdrini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm! Can't really test this ; just confirmed the beacon appearing in the networks panel.

Comment thread openlibrary/templates/site/head.html Outdated
Comment thread openlibrary/plugins/openlibrary/js/SearchFilterBar.js Outdated
Comment thread openlibrary/plugins/openlibrary/js/search-modal/SearchModal.js Outdated
Co-authored-by: Drini Cami <cdrini@gmail.com>
@cdrini cdrini removed the Needs: Review This issue/PR needs to be reviewed in order to be closed or merged (see comments). [managed] label Jun 25, 2026
@cdrini
cdrini merged commit a0ddc54 into internetarchive:master Jun 25, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify Matomo is receiving the new search-funnel events from #12948

2 participants