How to track site search in Google Analytics 4

Site Search is an essential element of almost every website nowadays. Therefore it’s crucial to track site search in Google Analytics 4 to find additional ways to improve your blogs, produce new products and build new integrations. All of that will help you to boost your company revenue and get new clients. 

Because of the potential hidden under the website search, many people wonder how to track it in GA4 successfully. This article will answer all these questions. Let’s start with the first one, why you need to track it. 

Why do you need to track the website search?

As I mentioned above, analysing website search usage can boost your revenue. There are a few main situations when it can be so important, and all of them are relevant to almost any website noways, including Ecommerce, SaaS, blogs and, more specifically, marketplaces.

Firstly, if you are an Ecommerce company that sells products online. It’s viable for you to track what other products your customers can be interested in. If you satisfy their needs by selling more products, you will increase average order value (AOV) and boost your revenue. As a result, you will be able to spend more on ads and compete with brands you couldn’t before, or you will be able to run ads on platforms that weren’t profitable back. 

Secondly, suppose you are a SaaS company with integration pages (where you show other products your product can be synced with). TryShift has one. You can track the site search in GA4 to understand what other products should be integrated with your app to convert more free trial users. If you measure it correctly and develop new relevant integrations, you will increase the trial-to-paid conversion ratio and overall revenue.

Thirdly, you can run a blog, and the site search can inspire you to write other articles your blog visitors are interested in. For instance, on my website, people searched for “GA4 certificate”; therefore, I came up with an article to explain how to get it. 

Fourthly, there is no doubt that if you are a marketplace such as Amazon or eBay or working in a travel niche such as, it’s crucial to optimise the website search because it’s a primary part of your funnel. The importance of that becomes more evident when you know that by working with on the website search, I could increase the sign-up ratio by 58%.

All of the above induces you to consider implementing website search tracking in Google Analytics 4. Moreover, GA4 implementation process is much easier than it was in Universal Analytics. 

How to set up site search tracking in Google Analytics 4

There are two ways to set up site search tracking in Google Analytics 4:

  1. using Google Analytics interface (recommended)
  2. using Google Tag Manager (mainly for those who can’t use the first version)

I recommend using the first version if your website follows the GA4 logic. There is no need to use a complex one. 

How to set up site search tracking using GA4 interface

As mentioned above, let’s use the first method to set up site search tracking in GA4. You need to follow a few simple steps:

Visit your website and use the website search and look at the URL it produces. For instance, when I use the website search on my website, the URL looks the following way.

Step 1 Checking Site Search Result Page URL
Step 1 Checking your search result page URL

Now, open GA4 -> Admin -> Data Streams -> “Enhanced Measurement” -> Click on the gear icon and activate “Site Search”. After that, click on “Show advanced settings”

Step 2 Navigating to GA4 Site Search Settings
Step 2 Navigating to GA4 Site Search Settings

Now, look at the URL once again; if you see “q”, “s”, “search”, “query” or “keyword” you don’t need to input it into GA4 because GA4 automatically recognises it, if you have something else, then provide it here. For instance, my website search page URL includes “s”, therefore, I don’t need to provide anything. Once you make the necessary changes, please remember to save the changes. After that, GA4 will start to track the website search. 

Step 3 Adjusting GA4 Site Search Settings
Step 3 Provide the correct search parameter here

Sometimes there is an additional query parameter in the URL, as in the example below. In this case, you can be interested in tracking it as well. GA4 allows you to do it quickly. You should provide the value (in my case, “category”) in the “Additional Query Parameters” field. 

Website URL with More Search Parameters
Website URL with more than one search parameter
GA4 Search Settings with more parameters
Step #4 Provide the second search parameter into GA4

However, there are situations when your URL doesn’t follow the logic GA4 uses to detect the site search. In this case, you should use Google Tag Manager to track the search on your website. 

How to set up site search tracking using GTM

My research revealed that there are 4 situations when you need to develop a custom solution to track site searches in GA4. All of them can be resolved with Google Tag Manager, but for the last one, you need to use the help of your engineers. 

Search Result Page URL includes the search term

Sometimes your Result Page URL includes the search term but doesn’t follow GA4 logic. For instance, you can have the following URL:

Website URL with Custom Search Path
Custom Search Results Page URL

You still have the search term in the URL, but it isn’t presented as a query parameter. Therefore Google Analytics 4 can recognise it by default. So to track it, you should create a custom javascript function variable in Google Tag Manager, extract the search term from the URL, and send it with the event into Google Analytics 4.

js gtm variable
JavaScript GTM Varialbe

Let’s open GTM and go to Variables and create a new one. Select the type “custom javascript” and name it “js – search term”. Input the following code.

function() {

  var pagePath = window.location.pathname;

  var searchParam = '/search/';

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

    return decodeURI(pagePath.split(searchParam)[1].split('/')[0])


Custom Site Search GTM Tag Incomplete
GA4 Tag Settings

After that, go to Tags tab and create a new Tag, select GA4 event for the type and provide the following attributes:

  1. Event Name – “view_search_results”
  2. Event Parameters
    1. Name – search_term
    2. Value – “js – search term” (the variable we created early) 
Custom Site Search GTM Trigger
GA4 Trigger Settings

Once you are done with that, you should add the trigger to this tag. To do that, follow these steps:

  1. Click on Add New Trigger
  2. Select Page View
  3. Provide the following parameter
    1. js – search term does not match regex (ignore case) ^(undefined|null|0|false|NaN|)$
Custom Site Search GTM Tag Complete
Complete GA4 Tag

Once you create this tag, remember to test and publish the GTM container. Once you publish it, GA4 will start to record the site search terms.

Tracking Search Result Page using dataLayer

If you didn’t succeed with the versions mentioned above, you need to ask your developers to help you set up site search tracking for GA4. Here is a piece of code you can provide to them to add to the search results page whenever a user uses the search. 


window.dataLayer = window.dataLayer || [];


  'event' : ‘view_search_results',

  ‘search_term’ : "{{search term used by user, dynamically changed}}"



When they implement it on the website, you can use Google Tag Manager to set up the GA4 event, use the data from the data layer, and send it into GA4. You can see an example of that in the screenshots below.

Once we are done tracking site search results, it can be beneficial for you to track searches with zero results. It will help you to look at the users who searched for something and left your website. It’s even more important to track than general site search tracking.

How to track search results page with zero results in GA4

Almost every website gives you a page with some information when there weren’t any results found. For instance, look at the example of my website below. 

Not Found Search Results

Therefore, you can use the element visibility trigger in Google Tag Manager to track no search results event. Let’s look at the steps.

No Search Results - GTM Tag Complete
No Search Results – GTM Tag Complete

First, let’s create the tag to fire the GA4 event tag.

Tag Name –  “GA4 – Event – No Search Results”

Tag Type  – “Google Analytics: GA4 Event”

Event Name – “no_search_results”

Event Parameter – “search_term”

Value – “{{search term}}”. Here you should select the variable that shows the term used by a user.

Next, For my website that follows the GA4 site search logic and has “s” query in page path, I created the following dataLayer variable “eventModel.search_term”.

No Search Results - GTM Variable
No Search Results – GTM Variable

After that, we should add the trigger to the tag. I used the following settings for my website:

  1. Trigger Type –  “Element Visibility”
  2. Click on “Some Visibility Events”
  3. CSS Selector “#main > div > section”
  4. Page URL contains “”
  5. Click Classes equals “no-results not-found”
No Search Results - GTM Trigger
No Search Results – GTM Trigger

After that, I got the event (no-search results) into GA4 with the correct parameters. You can do the same for your website. The idea is to read the element that appears whenever the search returns 0 results using element visibility and use it as a trigger in GA4.

GA4 DebugView No Search Results
GA4 DebugView No Search Results

Where to find site search data in GA4?

When you make the necessary adjustments to track site search in Google Analytics 4. You can be interested in finding this data. There are a few ways to find it in GA4, and the best one is to build a report in GA4 Explorations. Here are the steps you do follow to find site search data in GA4:

Option #1

  1. Open GA4 and go to -> GA4 Explorations and create a new report.
  2. Import the following dimensions and metrics:
    1. Metrics:
      1. Event count
    2. Dimensions:
      1. Search Term
      2. Event Name
  3. After that, add the dimension “Search Term” to “Rows” and Event count to “Values”. When it’’s done, you should add “Event Name” to filters and select “exactly matches “view_search_results”  or “no_search_results” if you want to see the search terms of searches that ended with null results. 

You should get the exact report you can see in the screenshot below.

GA4 Explorations - Site Search Terms
Monitoring site search terms in GA4 Explorations

Option #2

Besides using GA4 Explorations, you can find site search data in GA4 -> Reports -> Engagement -> Event: Event Name. Click on “view_search_results” event in the sheet. 

After that, you should select “search_term” in “Events in the last 30 mins”, and you will see them. This report can be helpful when you want to see real-time information. Otherwise, it won’t be so valuable. Therefore, I have a better solution for measuring site searches in GA4 – build a GA4 dashboard. 

Monitoring Real-Time Site Search

How to build a dashboard in GA4 to monitor site searches?

You can build your own dashboard in Google Analytics 4 to track site searches and searches ended with null results. However, each of them will require you to set up “search_term” event parameter as a custom dimension in Google Analytics 4. This feature became available on the 3rd of November, 2022.

Step #1

Search Term GA4 Custom Dimension
Step #1: Create “search_term” custom dimension

To convert “search_term” into the custom dimension, you should go to GA4 -> Admin -> Custom Definitions and click on the “Create custom dimensions” button. After that, you should provide the same settings as you can see in the screenshot below. Please remember that the data for this custom dimension will be available only from the exact moment you add it. The retrospective data won’t be available. So you can decide to wait a few days to collect your first data before building a report. 

Step #2

Step #2 Building Dashboard
Step #2: Create a new report in GA4 Library

After you have the first data to work with, you should go to GA4 -> Reports -> Library and click on “Create new report” and select “Create a detailed report”.  I recommend selecting “Events” as the template, it will speed up the process. 

Step #3

Step #3 Building Dashboard
Step #3: Adjust settings in the report to show the relevant search data

Now, let’s delve deeper into how to set up Site Search dashboard in GA4.

Firstly, change the dimensions. Instead of “Event name”, select “search_term” (custom) and click “apply”.

Secondly, change metrics, I recommend removing all and leaving only two “Event count” and “Total Users”. After you remove all the rest events, click on “apply”. 

Thirdly, add the filter to “Report Filter” using your new custom dimension “search_term”. 

Fourthly, change the summary card dimension from “Event Name” to “search_term”.

You can change other settings, but, from my perspective, it’s enough to measure site search tracking in GA4. In the end, remember to save a report and give it a name. For instance, “Website Search”.

Step #4

Adding the new report into GA4 Collection
Step #4: Add the new report into GA4 Collection

Once you save the report, you can add it to one of the published collections and use it daily. To do that, you should click on “edit collection”, for instance, “Life Cycle” collection. 

After that, you can create a new topic inside the collection or add a detailed report to the existing one. For this article, I add it to the existing “Engagement” topic. Save it and publish the collection. 

If you do everything right, you can enjoy your new Website Search dashboard in GA4. 

Final Thought

Site search is a crucial feature of every website nowadays. Usually, users who used your website search have a 3 times greater conversion than those who didn’t. Therefore, optimising it and engaging more users to use it is necessary. In this article, I explained how you could track website searches using Google Analytics 4 and presented a few ways to visualise the results when you get your first data to play with.

If you have any questions about this topic, please comment below.

How to track the website site search with GA4?

GA4 tracks website search automatically using Enhanced Measurement. If you want to modify the GA4 settings, you can go to GA4 -> Admin -> Data Streams -> “Enhanced Measurement” -> Click on the gear icon and activate “Site Search”. After that, you can change the settings by clicking on “Show advanced settings”.

How do I find search terms in GA4?

The best way to track search terms used on your website is to use GA4 Explorations. You can build a report with the dimensions “Search Term”, “Event Name”, and “Event count” as a metric.

Leave a comment

Your email address will not be published. Required fields are marked *