← Back to Trustlytics Sign in

Set up search

This is how you see what your visitors search for on your website. Which terms are in demand? Which ones return no hits and show you where a piece of content is missing? And which pages do your visitors open after searching?

Two ways, same result:

The video is in the works. Until then, the guide will get you there.

Step-by-step guide

What is search tracking?

If you have a search box on your website, somebody may be typing "pricing", "contact" or "shoes size 10" into it. Those terms are worth their weight in gold. They show you in black and white what your visitors really want.

Trustlytics collects every search term in a list. You see what was searched for most often, what ran into nothing, and which pages got clicked afterward.

Requirement: the Trustlytics tracking code has to be installed on your website. If it is not yet, take a look at the article Add the tracking code first. It takes under five minutes.

How Trustlytics detects a search

A search can happen in three ways. All you need to know is which one applies to you. In most cases there is nothing for you to do, because Trustlytics detects it by itself.

The three routes:

  1. Classic search. The search term sits in the URL (?q=shoes for example). Trustlytics detects that automatically.
  2. JavaScript search. The results get loaded in without the URL changing. Here you set a small hint.
  3. Single page app. Your app writes the search into the URL. Trustlytics detects that automatically.

Option 1: classic search with a URL parameter

This is the normal case. If your search looks like this:


example.com/search?q=shoes

or like this:


example.com/?search=pricing

then Trustlytics detects the search automatically. There is nothing for you to do.

Trustlytics knows these common parameters without any setup:

  • q
  • query
  • s
  • search
  • searchword
  • k
  • keyword

If your search also sends a category along ("search in products only" for example), these parameters are read as the category automatically:

  • cats
  • category
  • search_cat

If your search uses its own parameters

Some websites use their own names like ?find=, ?lookup= or ?term=. Trustlytics cannot guess those. You enter the name once, and everything runs by itself from then on.

Here is how:

  1. Go to Settings (the gear) → Search tracking.
  2. Under "Custom parameters" enter the parameter name (find, for example).
  3. Click "Add".

From now on Trustlytics detects that parameter automatically too.

Tip: you see the parameter name in your address bar as soon as you search for something on your own website. Everything between the ? and the = is the name.
Search: custom parameters - Trustlytics

Option 2: JavaScript search (the URL does not change)

If your search loads the results through JavaScript without the URL changing (typical with live search, where suggestions appear while you type), then Trustlytics needs a small hint.

As soon as results are displayed, you set two attributes on the <body> tag of your page. Here is what a <body> tag normally looks like:


<body>
 ...
</body>

You add the two attributes like this:


<body data-trustlytics-search="shoes"
 data-trustlytics-search-results="42">
 ...
</body>

You usually do not set these attributes by hand, your JavaScript code takes care of it. When your search box loads the results after typing, your code writes something like this:


// After a successful search:
document.body.dataset.trustlyticsSearch = userSearchTerm;
document.body.dataset.trustlyticsSearchResults = String(resultCount);

Trustlytics notices the change by itself and counts the search.

The attributes in detail

Trustlytics picks up these attributes automatically. There is nothing extra for you to configure:

Attribute Required? Example Description
data-trustlytics-search yes "shoes" The term that was searched for
data-trustlytics-search-results no "42" Number of hits (or 0 if there were none)
data-trustlytics-search-category no "Products" A filter category

You may leave out the hit count (data-trustlytics-search-results) if you cannot determine it. Trustlytics then simply shows no number in the report. But if you can, send 0 along as soon as a search returned no hits. That is the single most valuable piece of information there is (the "No results" area in the report).

Why a two second delay?

If your search box shows results while people type, Trustlytics would otherwise count a separate search for every single letter. That would be useless.

So Trustlytics waits two seconds to see whether another change comes in. Only the last entry before the pause gets counted. If somebody types "shoe" and two seconds later extends it to "shoes", Trustlytics counts "shoes" alone. Not "s", "sh", "sho", "shoe".

Option 3: single page app with a URL change

If you use React Router, Vue Router, Next.js, or a similar framework and your app writes the search into the URL (/search?q=shoes for example, without the page fully reloading), then Trustlytics detects that automatically.

Requirement: the URL parameter (q, search and so on) is in the standard list, or you added it in the settings, see above.

How to check that it works

  1. Set up your search as described above.
  2. Open your website in a new browser window.
  3. Type something into the search box and press Enter (or wait for the results).
  4. Wait until the next morning.

The term then shows up in the "Search terms" table.

Seeing nothing? Usually the parameter is not entered yet or the attribute is spelled wrong. Take another calm look at it.
Search: checking that it works - Trustlytics

Rules and limits

What Rule
Search term 200 characters maximum, any language
Number of hits any number from 0 to 999,999
Category 100 characters maximum, any language
Searches per visit 50 maximum (anti-spam protection)
Delay with live search 2 seconds between the last keystroke and the count

Privacy

Bot searches (search engine crawlers and the like) get filtered out automatically.

One request: no personal data in the search. If your search box also takes email addresses or names, those will turn up in the report. Best to filter them out before you pass anything to data-trustlytics-search.

Common questions

What if somebody cancels the search without pressing Enter?
Then nothing gets counted. Trustlytics only counts once a search was actually carried out (a URL change or the attributes being set on the <body>).

Are bots counted?
No. Crawlers from Google, Bing, ChatGPT, and so on are detected automatically and do not show up in the statistics.

How accurate is the counting?
Accurate. Every search gets saved. The current day is evaluated live, the values from the previous day appear final the next morning.

Does this also work with React, Vue, or Next.js?
Yes. Setting the attributes on the <body> works in every framework. Just build it into your search component as soon as the results are there.

What if I have different searches on different pages (one for products, one for the blog, for example)?
Use the data-trustlytics-search-category attribute with its own value per search ("Products" and "Blog" for example). In the report you then see both categories separately.

What happens if I change a URL parameter later?
Old searches stay in the report. New searches with the new parameter get counted as soon as you have added it in the settings.

What if somebody searches for the same thing several times?
Every search counts separately. If somebody searches for "shoes" three times, that is three searches.

Was this article helpful?