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.
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:
- Classic search. The search term sits in the URL (
?q=shoesfor example). Trustlytics detects that automatically. - JavaScript search. The results get loaded in without the URL changing. Here you set a small hint.
- 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:
qqueryssearchsearchwordkkeyword
If your search also sends a category along ("search in products only" for example), these parameters are read as the category automatically:
catscategorysearch_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:
- Go to Settings (the gear) → Search tracking.
- Under "Custom parameters" enter the parameter name (
find, for example). - Click "Add".
From now on Trustlytics detects that parameter automatically too.
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.
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
- Set up your search as described above.
- Open your website in a new browser window.
- Type something into the search box and press Enter (or wait for the results).
- Wait until the next morning.
The term then shows up in the "Search terms" table.
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.