chore: add Algolia search click tracking#5005
Open
evwilkin wants to merge 3 commits into
Open
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>
Collaborator
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: |
Collaborator
|
Tested search and the terms showed up on Algolia |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: