chore: add Algolia search click tracking#5005
Conversation
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>
|
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: |
|
Tested search and the terms showed up on Algolia |
|
I tested a couple of search terms and both worked as expected - no clicks showed up as such. |
closes #5006
Summary
clickedObjectIDsAfterSearchevents with objectID, position, and queryIDsendBeacontransport so click events survive page navigationattachDocSearch()🤖 Generated with Claude Code
Testing
To test:
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.
Last updatetimestamp at the top is after your search: