Skip to content

Send searches to Google Tag Manager for search analytics - #6

Merged
notleowang merged 3 commits into
site-searchfrom
search-analytics
Dec 1, 2026
Merged

notleowang merged 3 commits into
site-searchfrom
search-analytics

Conversation

@notleowang

Copy link
Copy Markdown
Collaborator

Description

Adds search analytics for the review from @stockholmux on valkey-io#723, to be merged into site-search. Follows #5, which added the search page.

Every search, from the header and from the search page, is pushed to Google Tag Manager's data layer as a search event once typing pauses:

Field Value
search_term The query, cut to 100 characters
search_results How many results match it, 0 for a miss
search_location modal (header) or page (search page)
  • Misses: Pagefind matches loosely, so even a made-up word returns a few results, scoring about 0.001, while real searches, typos included, score 2 or more. Only results scoring at least 0.1 are counted, so nonsense searches report 0 and typos still count as hits.
  • Not counted: the same query twice in a row, queries that look like an email address, and an empty search box.
  • Why Tag Manager: valkey.io loads Google Analytics through the Linux Foundation's Tag Manager container (GTM-MFFCB7SR), not gtag.js. Pushing an event to the data layer for Tag Manager to forward is the approach recommended for this setup, and it keeps the site's consent settings in charge of whether anything is recorded.

Needed outside this repository

The event reaches GA4 once these are set up by whoever manages valkey.io's Tag Manager and GA4. Until then it isn't sent anywhere, so merging this doesn't change the current reports.

  1. Tag Manager: a Custom Event trigger for search, Data Layer Variables for the three fields, and a GA4 event tag sending them to the site's GA4 property.
  2. GA4: search_results and search_location registered as custom dimensions, so hits, misses and location appear in reports.
  3. Check: Tag Manager Preview and GA4 DebugView.

The search page's ?q= URL can also be recorded by GA4's own site search tracking, if it's switched on in the property's enhanced measurement.

Review items

  • 2. Search analytics (hits and misses), or a way to add them: done on the site side; the Tag Manager and GA4 setup above is still needed.

Commits

This branch also includes site-search's merge of upstream main (632fcb9, with valkey-io#808, the 9.2.1 release update), which hasn't been pushed to site-search yet. The analytics change is 1268a22.

Testing

Built locally (Zola 0.23.6, Pagefind 1.6.0) and checked in headless Chrome with all hosts but the local site blocked, so nothing was sent to Google:

  • /search/?q=migration pushes search_term: "migration", search_results: 65, search_location: "page".
  • Made-up words (zzqxjv, qwxzvbn) push search_results: 0. The typo replicaton pushes 4.
  • A header search pushes search_location: "modal".
  • Repeating a search, an email address, or clearing the search box pushes nothing. A 130-character query is cut to 100.
  • Each event is a plain { event: 'search', … } object, as Tag Manager expects.
  • The search page still works, build/check-search-index.py reports 795 pages with 0 problems, and all 26 ranking cases pass.

Check List

  • Commits are signed per the DCO using --signoff

valkeyrie-ops Bot and others added 3 commits November 27, 2026 12:42
This pull request updates the valkey website for the new release 9.2.1.

Changes:
- Updated downloads page with new release information
- Updated Try Valkey page to use version 9.2.1

This pull request is created automatically by the
[Valkey-Release-Automation](https://github.com/valkey-io/valkey-release-automation)

---------

Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Signed-off-by: notleowang <leo.wang@improving.com>
Each search, from the header and from the search page, is pushed to
Google Tag Manager's data layer as a "search" event once typing pauses:
the query (search_term), how many results match it (search_results), and
where it was searched (search_location, "modal" or "page").

Pagefind matches loosely, so even a made-up word returns a few results,
scoring about 0.001, while real searches, typos included, score 2 or
more. Only results scoring at least 0.1 are counted, so a search with
search_results of 0 is a miss.

The same query isn't counted twice in a row. Queries that look like an
email address aren't sent, and queries are cut to 100 characters.

valkey.io loads Google Analytics through the Linux Foundation's Tag
Manager container, so the event reaches Analytics once a Custom Event
trigger for "search" and a GA4 event tag are set up there, along with
custom dimensions for search_results and search_location in GA4. Until
then it isn't sent anywhere.

Signed-off-by: notleowang <leo.wang@improving.com>
@notleowang notleowang self-assigned this Dec 1, 2026
@notleowang
notleowang merged commit 6efbfa9 into site-search Dec 1, 2026
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