Skip to content

chore: add Algolia search click tracking#5005

Open
evwilkin wants to merge 3 commits into
patternfly:mainfrom
evwilkin:chore/algolia-click-events
Open

chore: add Algolia search click tracking#5005
evwilkin wants to merge 3 commits into
patternfly:mainfrom
evwilkin:chore/algolia-click-events

Conversation

@evwilkin
Copy link
Copy Markdown
Member

@evwilkin evwilkin commented May 8, 2026

closes #5006

Summary

  • Adds Algolia search-insights library (CDN) to track search result clicks
  • Captures queryID via XHR interception since DocSearch v2 discards it from responses
  • Sends clickedObjectIDsAfterSearch events with objectID, position, and queryID
  • Uses sendBeacon transport so click events survive page navigation
  • Respects Do Not Track browser setting (same pattern as existing GA integration)
  • 404 page search inherits tracking automatically via shared attachDocSearch()

🤖 Generated with Claude Code

Testing

To test:

  1. Use the PR preview link to perform a search and click on a result. Note both the search term and the time you completed the search.
    Multiple searches can help confirm with more data points, but note that clicking on a search results takes you to the live site - use the back button from your search or reopen the preview link above to ensure any additional test searches start from the PR preview page.
  2. Open the Search page at Algolia.com and ensure it's filtered to today, then refresh the page until the Last update timestamp at the top is after your search: Screenshot 2026-05-11 at 10 22 50 AM
  3. Compare the "Search" tab with the "Searches without clicks" tab to ensure your search appears on the first but not the second.

evwilkin and others added 3 commits May 8, 2026 18:08
Track which search results users click to improve search relevance.
DocSearch v2 discards queryID from responses, so XHR interception
captures it to enable clickedObjectIDsAfterSearch with position data.
Uses sendBeacon transport to survive page navigation. Respects DNT.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
XMLHttpRequest doesn't exist in Node.js during server-side rendering.
Wrap the XHR prototype patching in a typeof check so it only runs
in browser environments.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@patternfly-build
Copy link
Copy Markdown
Collaborator

Preview: https://pf-org--pr-5005-site.surge.sh

@evwilkin evwilkin requested review from jschuler and phcox May 8, 2026 23:44
@jschuler
Copy link
Copy Markdown
Collaborator

The main thing that got flagged for me is this:

handleSelected overrides default navigation behavior (sideNavLayout.js:240-253)

The handleSelected callback ends with window.location.href = suggestion.url, re-implementing DocSearch's default navigation. If DocSearch's default behavior ever changes (e.g., SPA navigation, opening in new tab for modifier keys), this override won't pick that up. Notably, Cmd+Click / Ctrl+Click for "open in new tab" is broken — the handler unconditionally does window.location.href = ... regardless of modifier keys.

Consider checking for context === 'click' vs keyboard selection, and respecting modifier keys:

if (event.metaKey || event.ctrlKey) {
  window.open(suggestion.url, '_blank');
} else {
  window.location.href = suggestion.url;
}

@jschuler
Copy link
Copy Markdown
Collaborator

Tested search and the terms showed up on Algolia

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.

Enable click events in Algolia

3 participants