Skip to content

Site search

Every search on your own site, what people typed and which searches found nothing, read from the URL automatically or sent from your code.

What people search for on your site is the clearest list of what they want and cannot find. Statsy records each search as a site_search event and shows the top queries under Goals › Captured automatically, with the number that found nothing.

From the URL, with no code

When a page loads, or a single-page app changes route, the script looks for the first of these query parameters and takes its value as the search:

text
q   query   search   s   keyword   k

s is what WordPress uses, q most everything else, so most sites need no setup. The value is trimmed and cut at 256 characters, and the same query on the same page counts once per session even if the results page reloads.

If your search uses a different parameter, name it on the tag. Several are fine, comma separated.

html
<script defer data-website-id="ws_XXXXXXXX" data-search-params="term,find" src="https://statsy.co/js/script.js"></script>

From your code, with a results count

Searches that do not change the URL, a search-as-you-type box or a modal, need one line. Pass how many results came back and Statsy can tell you which searches found nothing.

js
statsy.search('blue shoes', results.length);
// or the same as a plain goal
statsy.goal('site_search', { query: 'blue shoes', results: 0 });

Call it when results arrive, not on every keystroke, or a ten-letter word becomes ten searches. Waiting until the visitor pauses for half a second is a good rule.

What you see

  • Top queries by searches, with visitors, for the selected period.
  • How many of each query's searches returned nothing, when you pass a count.
  • A total of empty searches across the period: your content gap list.
  • Filter any report by the event: name is site_search shows where searchers came from and whether they bought.

Tip. Search queries are text a visitor typed. If your visitors might type personal details into search, and that matters for your privacy notice, either switch URL capture off with data-track-search="false" and send only the queries you want, or send a normalised form of the query.

Frequently asked questions

Does this work with Algolia, Typesense or a headless search?

Yes. Those rarely change the URL, so use statsy.search(query, count) in the results callback.

Are searches of cookieless visitors recorded?

Yes. A site_search is a goal, and goals work in both modes. Only the visitor is anonymous.

Why is the results count missing for some queries?

Searches captured from the URL cannot know how many results the page showed. Send them from your code to include the count.

Last updated · Markdown version