Skip to content

Fix missing click analytics on /search/ results page#397

Open
JakeSCahill wants to merge 1 commit into
mainfrom
fix/search-page-click-analytics
Open

Fix missing click analytics on /search/ results page#397
JakeSCahill wants to merge 1 commit into
mainfrom
fix/search-page-click-analytics

Conversation

@JakeSCahill

Copy link
Copy Markdown
Contributor

Problem

Algolia Click & Conversion analytics showed little/no click data for docs search (CTR/CVR mostly N/A or 0%), and the top queries were dominated by two odd rows: <empty search> (~33% of searches) and {search_term_string}.

Root cause: we have two Algolia surfaces and only one was instrumented.

  • Autocomplete dropdown (src/partials/algolia-script.hbs) — fully wired: search-insights, aa('init'), insights: true, clickAnalytics: true, and clickedObjectIDsAfterSearch with queryID. ✅
  • Standalone /search/ results page (src/layouts/search.hbs) — InstantSearch with no insights, no clickAnalytics, and no click events sent. Every click from the full results page was invisible to Algolia. ❌

Since the bulk of "real" searching happens on /search/, most click data was missing and CVR sat at 0%.

Changes (src/layouts/search.hbs)

  1. Enable insights: true on the InstantSearch instance. It reuses the global aa (search-insights) already initialised in algolia-script.hbs with matching ALGOLIA_APP_ID/ALGOLIA_API_KEY, sets clickAnalytics, and attaches a queryID to each query.
  2. Wire sendEvent('click', hit, 'Hit Clicked') into the custom hit-template links. Custom hits templates don't get automatic click tracking, so this is required for clicks to record and attribute to the query. sendEvent uses navigator.sendBeacon, so it survives the navigation the link triggers.
  3. Suppress empty "root" queries from analytics via analytics: false. These fire on initial page load and during facet-only browsing (no term typed) and were logged as <empty search> (~33% of searches), dominating the report and skewing average CTR. Results still return — they're just not counted as a searched term. Using analytics: false (rather than blocking the request) preserves initial load and facet-only browsing.

Not changed

The {search_term_string} query (low volume, no clicks) is the sitelinks-searchbox SearchAction template in src/partials/head-structured-data.hbs (/search/?q={search_term_string}) being crawled literally by Google/bots. That's expected SEO behavior — left as-is; filter it out in the dashboard view if desired.

Testing

  • gulp lint passes.
  • Manual verification recommended on a deploy preview: perform a search on /search/, click a result, and confirm a Hit Clicked event appears in Algolia (Events debugger / Click analytics), and that a blank /search/ load no longer records an <empty search>.

🤖 Generated with Claude Code

The standalone /search/ InstantSearch page reported searches to Algolia
but never sent click/conversion events, so Click & Conversion analytics
showed little/no click data (CTR/CVR mostly N/A or 0%). Only the
autocomplete dropdown (algolia-script.hbs) was instrumented.

Changes:
- Enable `insights: true` on the InstantSearch instance. It reuses the
  global `aa` (search-insights) already initialised in algolia-script.hbs
  and attaches a queryID with clickAnalytics on each query.
- Wire `sendEvent('click', hit, 'Hit Clicked')` into the custom hit
  template links. Custom templates don't get automatic click tracking,
  so this is required for clicks to be recorded and attributed.
- Suppress empty "root" queries from analytics via `analytics: false`.
  These fire on initial page load and facet-only browsing and were being
  logged as "<empty search>" (~33% of searches), dominating the report
  and skewing average CTR. Results still return; they're just not counted
  as a searched term.

Note: the "{search_term_string}" query seen in analytics is the
sitelinks-searchbox SearchAction template in head-structured-data.hbs
being crawled literally by bots; it's expected SEO behavior and left
as-is.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@netlify

netlify Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploy Preview for docs-ui ready!

Name Link
🔨 Latest commit 6785a71
🔍 Latest deploy log https://app.netlify.com/projects/docs-ui/deploys/6a4d1e8280dfdb0008e8fffe
😎 Deploy Preview https://deploy-preview-397--docs-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 29 (🔴 down 1 from production)
Accessibility: 89 (no change from production)
Best Practices: 92 (no change from production)
SEO: 89 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 71859726-fd06-4bd5-83cc-138c42e9e262

📥 Commits

Reviewing files that changed from the base of the PR and between 42657e2 and 6785a71.

📒 Files selected for processing (1)
  • src/layouts/search.hbs

📝 Walkthrough

Walkthrough

The change updates the Algolia search-page template's search request wrapper to always normalize requests, disabling analytics for empty queries and conditionally applying exact-match overrides. InstantSearch initialization now enables insights. The hits rendering template adds a click handler using sendEvent, wiring it into both external and internal hit link markup for click-through attribution.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HitsTemplate
    participant InstantSearch
    participant AlgoliaAnalytics

    User->>HitsTemplate: clicks hit link
    HitsTemplate->>HitsTemplate: onHitClick(hit)
    HitsTemplate->>InstantSearch: sendEvent('click', hit)
    InstantSearch->>AlgoliaAnalytics: report click event (insights: true)
Loading

Related Issues: None linked in the provided summary.

Related PRs: None linked in the provided summary.

Suggested labels: search, analytics, enhancement

Suggested reviewers: None specified.

🐰 A search bar clicks, a hit gets tracked,
Analytics whispers where queries have backed,
Insights now glow, exact matches align,
Every click on a link now leaves a fine sign.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing missing click analytics on the /search/ results page.
Description check ✅ Passed The description directly explains the analytics issue, the fix in search.hbs, and the validation steps.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/search-page-click-analytics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant