For large websites that offer a broad range of products or services, it’s essential to track how visitors search within the site. This helps understand what users are looking for and how you can optimize your product assortment, as well as improve naming conventions for better user experience.
In Google Analytics 4 (GA4), you can easily set this up by configuring on-site search tracking:
☝ This feature allows you to monitor what search terms visitors are entering into your site’s search bar.
By enabling this feature, you can gain valuable insights, such as:
- Which products or pages users struggle to find.
- How users are phrasing their searches.
Let’s walk through how to configure on-site search tracking in GA4's new interface.
Steps to set up on-site search tracking in GA4
➊ Start by accessing your property settings, then navigate to Data Streams → Enhanced Measurement:
By default, on-site search tracking is turned on for all properties, but it’s important to fine-tune a few settings. Click the gear icon to access the advanced settings of the site search:
In many cases, the search parameters you need will already be configured. If you see your search parameter listed, you don’t need to make changes. In the previous version of Google Analytics, finding the right parameter often involved searching for it in the URL.
For example, on our website, the search URL looks like this:
site.com/search?query=chair
In this case, the key parameter is "query" (the part that comes after the ?). If your URL follows a similar structure, you don’t need to add anything. Simply save the settings.
➋ Create a custom definitions for the “search_term”:
* The “search_term” parameter in GA4 represents the actual search query users type into your site’s search bar.
* The event that logs these search results is called “view_search_results”. You can find this event both in DebugView for testing purposes and in your reports.
➌ Test your On-Site Search Setup using DebugView.
Important: You may need to wait up to 24 hours for the setup to take full effect in the system.
Use the GA4 Debugger or Tag Assistant, run a search on your site, and then look for the view_search_results event. This event will contain the search_term parameter, which represents the user’s search query.
If the event appears, everything is set up correctly. Now let’s see how you can access this data in your reports.
➍ In the reports section, you can view on-site search data by going to “events” → “view_search_results” → “custom” → “search_term”.
The result will look something like this:
This data is incredibly useful for understanding user behavior on your site specifically, what they’re having trouble finding and how they’re searching for it.
This is something we’ve implemented ourselves, and it works effectively no need to rely on external case studies or examples.
Note: If your site’s search function doesn’t change the URL, you’ll need to trigger the “view_search_results” event each time a search is performed, along with the “search_term” parameter.