Repository navigation
feat(docs-next): send a HockeyStack goal for each docs search - #340
Jesswinters wants to merge 3 commits into
Conversation
The docs search is a dialog, not a form submit, so HockeyStack cannot see what readers search for on its own. Both search dialogs now send the `Docs Search` goal with the trimmed term as `search_term`, once per search: after typing pauses for a second, or at once when a result is selected, and never twice for the same term. Empty searches send nothing, and the call is skipped until the HockeyStack tag has loaded. Assisted-by: AI
nickvigilante
left a comment
There was a problem hiding this comment.
The code looks right to me, and I couldn't find a correctness bug. One question needs an answer before merge, plus a few smaller notes.
Before merge: is sending raw search terms to HockeyStack OK with Security? This sends whatever readers type into search to a third party. People paste API tokens, email addresses, internal hostnames and error messages into docs search. No new CSP origin is added, so the AGENTS.md sign-off rule doesn't strictly apply, but it's still a new kind of reader input leaving the site. I'd like Lisa or JD to confirm it's fine. If they want it narrowed, two cheap options are capping search_term at around 100 characters, or skipping terms that look like secrets (for example a long run of characters with no spaces).
Smaller notes
- A pause mid-word counts as a search: typing "work", pausing a second, then finishing "workspace" sends two goals. That's a reasonable trade-off for a 1-second debounce, but it's worth telling marketing that the term list will include some partial words.
- The dedupe only resets when the input is cleared. If the dialog keeps its text between opens, closing and reopening search on the same term won't count again. Minor.
- Nit: "a search before HockeyStack has loaded does not throw" doesn't check that
window.HockeyStackis undefined. It relies on the previous test'st.afterhaving removed it. Anassert.equal(window.HockeyStack, undefined)at the start would make that explicit. - Nit: the body has an Asana link but no Linear link section, which AGENTS.md asks for.
What I checked and found fine
- Selecting a result still navigates. In fumadocs-ui 16.15.11,
SearchDialogrunsrouter.pushand closes the dialog before it calls theonSelectprop, so the new callback adds the goal without replacing navigation in either dialog. In the hybrid dialog, the{...props}spread comes afteronSelect, butSharedPropscarries noonSelect, so nothing overrides it. search-analytics.tsimports only React, so it adds nothing to the first-load bundle.- There's no CSP change, and the call does nothing until the tag has loaded, so it stays silent with
DOCS_ANALYTICSoff or before consent. - The tests cover the debounce, an immediate send on Enter with no duplicate, whitespace-only input, and the not-loaded case through both dialogs, with a shared stub in
test/hockeystack.ts.
|
@jdomeracki-coder and/or @Lisa-Fiander can one of you confirm that Security is okay with sending raw search terms to HockeyStack?
|
|
Hey @Jesswinters, a few things to cover and follow up on. From my understanding, search terms reach HockeyStack as free text, alongside whatever visitor and company identification its tag performs, and they're visible to everyone with HockeyStack dashboard access and exportable from it. The cookie consent banner (Osano) covers tracking readers who accept marketing cookies, but readers don't expect what they type into search to be sent along with it, such as tokens (including Coder API tokens), email addresses, internal hostnames and error messages with secrets in them. One reason to land all of this in this PR rather than as a follow-up: an archived version embeds whatever the engine built, and per Required before merge
Not blocking, but worth doing hereGuard the call: check QuestionsVendor review: has HockeyStack been through our vendor security review (SOC 2 / DPA)? I couldn't find it. Please also note its retention period and who has dashboard access. Consent category: HockeyStack loads on marketing consent only, and as a non-Google tag it ignores Consent Mode, so a reader who accepted marketing but declined analytics still has their searches captured. Should search capture also require analytics consent? This predates the PR, but the PR is what adds free text to it. If we want that without changing the GTM container, the hook can check CSP sign-off: ScopeI've confirmed this only fires on coder.com/docs for a reader who accepted marketing cookies. Previews, local builds and the offline export don't load the tag: the offline export is pinned three ways (turbo never passes Please keep |
Main's search dialogs now run on experimental_useSearch and take their results as data, so the conflicting dialog edits take main's version. The goal wiring is restored in the next commit. Assisted-by: AI
…eted searches The goal sent every typed term to HockeyStack, where it is visible and exportable, so pasted tokens, emails and logs could leave the reader's browser. It now sends a term only while the dialog is open, once the term has results, when it passes one shared filter (no run of 20 or more characters without spaces, no email, at most 100 characters, never truncated), and when Osano reports analytics consent as ACCEPT, failing closed otherwise. The filter runs on every send, because the debounce sends slowly typed terms as growing prefixes. The call is guarded against a HockeyStack tag of another shape, and a dismissed search clears its pending send. Assisted-by: AI
|
From @nickvigilante:
|
Merge order
Independent; merges on its own.
Summary
Marketing wants to see what readers search for on coder.com/docs in HockeyStack. The search is a dialog, not a form submit, so HockeyStack cannot capture it on its own. This sends the goal HockeyStack already has set up,
HockeyStack.goal('Docs Search', { search_term }), once per search.Design
A new hook,
useSearchGoalinpackages/docs-next/src/search-analytics.ts, is used by both search dialogs:HybridSearchDialog, which production uses becauseapps/docs/vercel.jsonsetsDOCS_SEMANTIC_SEARCH=1, andDocsSearchDialog, the keyword-only fallback. The hook sends the goal when typing has paused for 1 second, or at once when a result is selected by click or Enter. It never sends the same trimmed term twice in a row, so a select after the pause, or a re-render, does not count again. Clearing the input resets that, so searching the same term again later counts as a new search. The page URL is not sent, because HockeyStack records it on its own.Security's review of this PR (#340 (comment)) set the conditions for a send, and every one is checked on every send, including each debounced prefix: the dialog is open, so a term typed and then dismissed is never sent; the search returned at least one result for that exact term; the reader has accepted analytics consent; and the term passes one shared filter,
searchGoalTerm. That filter rejects an empty or whitespace-only term, a run of 20 or more characters without spaces (/[A-Za-z0-9_\-.+\/=]{20,}/), an email address, and anything over 100 characters, which is dropped and never truncated. Consent iswindow.Osano.cm.getConsent().ANALYTICS === "ACCEPT", and it fails closed: a missing Osano, agetConsentthat throws, a denied choice and a choice not yet made all send nothing. HockeyStack itself only loads after marketing consent, so the analytics check also covers a reader who accepted marketing and declined analytics. The call is guarded by atypeof window.HockeyStack?.goal === "function"check and atry/catch, so a tag that has not loaded or has changed shape never throws.No new script, origin or CSP change: this calls the HockeyStack tag that coder.com's tag manager already loads under the existing analytics policy.
Decisions
DOCS_SEMANTIC_SEARCHis off, so both are wired to the same hook.search_term: query.trim()).workspace-proxy-configurationor a full environment variable name, and a test pins that. Security suggested requiring a digit in the run if that is too lossy.abcdefghijmay already have been sent. That comes with the debounce.getConsent()beyond that (ARCHITECTURE.md says so).onSelectcalls the send for every item. Once fix(search): rank matching sections and expand grouped results #288 merges, its "Show more" action rows would call it too. That is safe, because the term still has to pass the filter and have results, but the handler could skip action rows.Still open with Security: HockeyStack's vendor review (SOC 2, DPA), its retention period and who has dashboard access, and where the CSP origins for
/docswere approved. coder.com'snext.config.jsalready carries the same 19 analytics origins in its/docspolicy asANALYTICS_SCRIPT_ORIGINShere.QA
window.HockeyStackis undefined in the console (analytics off on the preview), pastewindow.HockeyStack = { goal: (...a) => console.log("goal", ...a) }first, and thenwindow.Osano = { cm: { getConsent: () => ({ ANALYTICS: "ACCEPT" }) } }. Nothing is sent without that consent. On production, where the real tag and consent banner are loaded, use the HockeyStack dashboard instead.workspace proxyat normal speed, then stop. About 1 second later, the console shows one line:goal Docs Search {search_term: 'workspace proxy'}. Nothing is logged while you type.(spaces only), and wait. Nothing is logged.agent, then press Enter at once, before 1 second passes. One line foragentis logged straight away.zzzzqqqq(no results) and wait. Nothing is logged.abcdefghijklmnopqrstuvwxy(25 characters, no spaces) and wait. Nothing is logged. The same happens forme@example.com.workspace proxy, then press Escape before 1 second passes. Nothing is logged.window.Osano = { cm: { getConsent: () => ({ ANALYTICS: "DENY" }) } }, then repeat step 3. Nothing is logged.Not verified in Firefox.
Pages to compare
The preview needs
docs-pr-preview.ymlrun on this branch, and its alias needs a Vercel login.Docs Searchgoal per searchdocs-pr-preview.ymlrun onvigilante/docs-search-hockeystackTesting
search-dialog.test.tsxrender the dialog with a stubbedwindow.HockeyStackandwindow.Osanoand cover: one goal for the settled term after several keystrokes, an immediate goal on Enter with no duplicate after the delay, no goal for an empty or whitespace-only search, a zero-result search, results left over from an earlier term, a cancelled search (including that reopening with the same term sends again), consent denied, not chosen, absent andgetConsentthrowing, and HockeyStack absent, with the wrong shape, or throwing.hybrid-search.test.tsxcovers the debounce, a zero-result search and a dismissed search through the hybrid dialog, andsearch-analytics.test.tscovers the shared term filter: a token, an email, a 101-character term, and a 100-character term that is sent.errorlistener catches the timer's throw. The tests for a normal term, an immediate send on Enter, the 100-character term and an absent tag pass on both by design.typecheckclean, oxfmt and oxlint clean on the changed files. No browser was available, so the QA steps above are unrun, andactionlintwas not run.Upstream
No. This is Coder's own analytics, not a Fumadocs feature.
Generated by Coder Agents on behalf of @Jesswinters.
🤖 Built with AI assistance.