How to set up site search tracking in GA 4?

Пошук по сайту в Google Analytics 4 Web analytics

Tracking site searches in Google Analytics 4 is necessary when you want to understand what exactly visitors are looking for, what search queries they use, and how they behave after they didn’t find what they were looking for. This is especially true for large websites with a complex structure and a large number of pages.

However, accessing this information is not so easy. By default, Google Analytics does not track requests within a site. Moreover, the process of setting up this function in GA4 also differs from the one everyone is used to in Universal Analytics. So how can you track website searches in Google Analytics 4? We’ll help you figure this out further.

Why is it important to track site searches?

By tracking internal search on a website, the owner of an Internet resource can:

  • Identify which products are missing for online store visitors. For example, if visitors are frequently looking for a specific product that is out of stock, this is a clear signal that you should think about expanding your assortment or restocking your inventory. In this way, you will make the resource more useful and relevant to the target audience, which will have a positive effect on traffic, conversions and income.
  • Identify possible navigation problems. It happens that the necessary information is on the site, but users cannot find it due to an ill-thought-out structure. Query analysis will help identify such “blind spots” and optimize usability. For example, move a popular section to the main menu or add cross-links and banners.
  • Understand the intentions and needs of the audience. By tracking what and how visitors search, you will better understand their interests, pain points and desires. This knowledge will help you create more relevant content, optimize advertising campaigns and increase conversion.
  • Assess the relevance of search results. It’s not enough to just add a search to your site; it’s important that it produces truly useful results. By comparing the most popular user queries with what pages are found on them, you will be able to evaluate the result obtained and, possibly, modify the plugin responsible for internal search with the help of a programmer.
  • Get ideas for new content. If you are the owner of an information site, then in this way you can find out what topic to write an article on to get additional traffic. By analyzing the frequency and semantics of requested phrases, you can find topics for creating new content or expanding old ones. Even if search queries are formulated differently, you can capture the general interest of the audience in a particular issue.

Although the basic principles of site search tracking in Google Analytics 4 and UA are similar, there are a number of significant differences:

  1. In Universal Analytics, you must manually assign a query parameter to the view, such as “q” or “search”. In the fourth version, five standard options are available by default (q, s, search, query, keyword), from which the system selects the appropriate one automatically. But if necessary, you can add your own options.
  2. If in UA you need to specify a search query parameter in the URL to collect statistics, now the system simply registers a special event “view_search_results” at the moment when visitors search for something on the site. This event contains not only the search query itself, but also, for example, the number of results found, which greatly simplifies configuration and details the statistics.
  3. In UA, only the total number of requests, failure rates, and popular keywords were recorded. In the new version of Analytics, based on the data received, you can build reports and create segments, use funnels and paths to track what users do before and after the actions performed.
  4. In the old version, internal search traffic was treated as a separate data type, loosely related to other metrics. The GA4 event model allows you to analyze it in conjunction with other events – page views, clicks, purchases, etc. This gives a holistic picture of behavioral factors.

How to define an internal search query parameter?

Open a web resource in a browser and enter any keywords into the search bar. It is usually located in the header or side menu. After that, press Enter on your keyboard or click on the “Find” button with your mouse to see the search results.

Next, go to the address bar of your browser. There you can find the full URL of the page, including the query parameter. That’s exactly what we need. It is usually located after the (?) sign and consists of a key and a value separated by an equal sign (=). For example, for a WordPress resource it is “s”:

Defining the site search page parameter

Please note that the parameter may differ depending on the CMS or script used. For example, for OpenCart it is “search”, for Horoshop and Magento it is “q”, OkayCMS is “keyword”, and is “search_term”.

How to set up site search tracking in Google Analytics 4?

To set up site search tracking in Google Analytics 4, open the “Admin” section in the system (gear icon at the bottom left). Select the required resource and go to “Data Streams”.

Opening data streams

Find the desired stream or create a new one by specifying the link and name. When creating a new stream, improved statistics are automatically added. If you are editing an existing one, make sure the switch is active.

Enable improved statistics in GA4

Additionally, go to settings and make sure that the switch opposite the “Site Search” function itself was in the active position:

Enable site search tracking

Add search query parameters. The most popular ones are already active by default, so for sites using common CMS, this step can be skipped. If the required parameter is not in the list, then you need to enter it manually, separated by commas. There is no need to use a space. Also, do not append an equal sign to the parameter or the variable itself (search term).

Available parameters by default

There are also cases when you need to track the category in which the user searches, the page where the action is performed, etc. This information also goes into the URL parameters:

 Search category

Google allows you to track the category, as well as other additional criteria. You can enter them in a special field:

Field for additional request parameters

To see not only the number of searches, but also the phrases themselves, you need to create an additional parameter. In the “Property settings” section, go to “Custom definitions” and click on “Create custom dimension”.

Create a special parameter

There, come up with a name for the parameter, area and select “search_term”. After this, save all changes made.

Set a name for the event parameter

How to check if site search tracking is working in GA4?

To make sure everything works, install the GA Debugger extension, which is available for Chrome and Firefox. Go to your web resource and check that the extension is enabled (it should say “ON”). Next, you need to enter any search query so that information about it gets into Analytics.

Google Analytics Debugger extension

After that, go to the analytical service again and open the DebugView (debugging) section:

 Debug mode

In the list of monitored events you need to find “view_search_results”. Click on it and find the line “search_term” in the drop-down list. The keyword you entered should appear there. If it is there, then everything is in order:

Receiving the search query

Another way to track site searches in GA4 is to use the Real-Time Reports tool. Go to the Live View tool and look for Events. There we need to find “view_search_results”. If it appears after performing a search, then everything is working.

Live view

Please note that even if an event is captured correctly in debugging tools, it may not be immediately visible in standard reporting. This is due to Google’s privacy policy. To protect users’ personal data, the system does not show the text of queries until a certain number of identical options have accumulated. The exact threshold is unknown and is internal information of the service.

Therefore, if you do not see the necessary data after some time, this does not necessarily mean that tracking is not working. Perhaps there simply was not enough data to display them. Continue to accumulate statistics and check your reports regularly. As soon as the number of keywords exceeds the privacy threshold, you will begin to see all phrases and will be able to use them for analysis and optimization.

Remember that the information in the tool is typically updated on a 24-48 hour lag. Therefore, if the setup was completed relatively recently, do not expect instant statistics to appear in the reporting.

Other ways to track site search in Google Analytics 4

The standard method of tracking site searches in Google Analytics 4 using parameters in the address bar works well for most sites. However, if internal search is implemented using JavaScript and does not change the page URL, this method will not work. Fortunately, there is an alternative solution – Google Tag Manager.

To activate it, go to the “Variables” section in Google Tag Manager and create a new one. The type must be selected “Custom JavaScript”. Next, paste the following code:

function () {

var pagePath = window.location.pathname;

var searchParam = ‘/pages/search/’;

if (pagePath.indexOf (searchParam)> -1) {

return searchParam + ‘? s =’ + pagePath.split(searchParam)[1].split(‘/’)[0]



In the “searchParam” variable, specify the part of the URL that precedes the request. If the page address is, enter ‘/search/’.

If the URL looks like, enter ‘/search/results/’. Save the variable, giving it a clear name, for example, “JS – SearchQuery”.

After this, you need to send the value of the newly created variable to Analytics. Go to the Tags section in GTM and find your existing Page View tag. If it is missing, create a new one.

In the tag configurations, activate the “Enable settings override” option. Expand “Advanced” and go to “Fields to customize.” Click on the “Add Field” button and fill in the name and value of the variable (as in the screenshot):

Enable overriding settings

Save changes to the tag. Now, when the tag is fired, the Page View event will not contain the real URL, but the value of a custom variable:

Checking the functionality of the event

In GA itself, you need to add a new variable in the same way as with the standard setup. Use “s” as the variable.

Now, when the system receives a Page View event with a page_path parameter starting with “/search?s=”, it will automatically extract the request text and store it in the “search_term” parameter. The statistics collected can be used to analyze phrases entered by users on the website.

Сергей Шевченко
Rate author
Add a comment

Sergey Shevchenko Google Logist GoogleLogist
Google Ads 90 Days Package, will help make your advertising campaign not only profitable, but also increase sales from it