Updated: January 16, 2025
This article introduces Site Search in GA4.
Site Search Settings
Method 1 : Enhanced Measurement Events
If the URL structure of your website’s search page is https://www.bbccss.com/?search=gtm, that is, search=search term, you can directly enable enhanced measurement events in GA4.
Enhanced measurement settings in Web stream details:
Click the gear icon to see the enhanced measurement settings interface, then check 「Site search」:
By default, the search query parameters are q, s, search, query, and keyword. As long as there is a search=search term structure in the URL, the event view_search_results will be triggered. The search term is in search_term.
You can also customize some query parameters in Additional Query Parameters. You can enter up to 10 parameters, separated by commas.
Read More : GA4 Event Tracking Series ② —— Enhanced Measurement Events
Method 2 : Custom Events
If the URL structure of your website’s search page is https://www.bbccss.com/search/GTM, you cannot use enhanced measurement events. You need to use custom event tracking. The following shows you how to set it up:
Step 1 : Set Up the Variables
First get the search term from the Page URL.
In GTM , click「Triggers」——「New」——「Choose a trigger type to begin setup…」——「Custom JavaScript」,Name it “search term”, and make the following settings:
The sample code may not apply to you. You need to write the JavaScript Code to get the term from according to your actual Page URL.
Step 2 : Set Up the Trigger
In GTM , click「Triggers」——「New」——「Choose a trigger type to begin setup…」——「Page View」,Name it “search”, and make the following settings:
Step 3 : Set Up the Tags
In GTM , click「Tags」——「New」——「Choose a tags type to begin setup…」——「Google Analytics: GA4 Event」,Name it “GA4-Event-view_search_results”, and make the following settings:
Try to use the event names and event parameters in Enhanced Measurement Events.
Step 4 : Preview and Publish
Next is preview debugging.
Tags is triggered and can be published.
Read More:
Method 3 : dataLayer.push
If it is a single-page application (SPA) and the URL remains unchanged, the custom events in the previous method may not be applicable. In this case, you can consider using the dataLayer.push method to actively send events.
Read More:GA4 Event Tracking Series ⑩ —— Custom Events (dataLayer.push Method)
View Site Search Data In GA4
The default event name for GA4’s site search is view_search_results, and the search terms are in search_term. Next, let’s see how to view on-site search keywords in the report.
Report
In the GA4 event report, you can see the view_search_results event:
Here you can only see how many times the user has searched. If you want to see what specific keywords the user has searched, you need to look in Explore.
Explore
In GA4, click “「Explore」 —— 「Freeform」 and make the following configuration:
- Row: search_term
- Value: Event count
- Filters: Event name Contains view_search_results
You can see the number of events for each search term in the canvas on the right:
FAQ
99% of the Search Terms are Blank
You probably didn’t filter out view_search_results. The default is all events. Other events don’t have search terms, so they are blank.
Read More :Over 90% of Search Terms in GA4 are Blank?
view_search_results event is not triggered
If your website is front-end and back-end separated or SPA, even if the URL meets the requirements, the view_search_results event will not be triggered.
The solution is to use the dataLayer.push method to track.