How to Track Site Search in Google Analytics 4 (3 Methods)

Google Analytics BCS 7 years ago (2019-12-12) 3328 Views 0 Comments
文章目录[隐藏]

Updated: May 27, 2025

This article explains how to implement and analyze Site Search tracking in Google Analytics 4 (GA4) using different tracking methods depending on your website structure.

Site search tracking is based on the GA4 event view_search_results, with the search keyword stored in the parameter search_term.

Site Search Configuration in GA4 (3 Methods)

GA4 does not rely on a single fixed setup. The correct implementation depends on how your site handles search URLs and routing logic.

Method 1 : Enhanced Measurement Events (Recommended for Standard Websites)

This is the simplest and most common approach.

When to use it

Use Enhanced Measurement if your search URLs contain query parameters such as: https://www.bbccss.com/?search=gtm, Here, search=gtm is the query-based search structure.

How it works

GA4 automatically detects common query parameters such as q, s, search, query, and keyword.

When a supported parameter is detected, GA4 automatically triggers:

  • Event: view_search_results
  • Parameter: search_term

Configuration steps

Enhanced measurement settings in Web stream details:

How to Track Site Search in Google Analytics 4 (3 Methods)

 

Click the gear icon to see the enhanced measurement settings interface, then check 「Site search」:

How to Track Site Search in Google Analytics 4 (3 Methods)

You may define up to 10 additional parameters, separated by commas.

Read More : GA4 Event Tracking Series ② —— Enhanced Measurement Events

 

Method 2 : Custom Events Via GTM

This method is required when URLs do not use query parameters.

When to use it

Use this approach if your search URL looks like: https://www.bbccss.com/search/GTM, In this case, the search term is part of the URL path, not a query parameter, so Enhanced Measurement cannot detect it.

Step 1 : Set Up the Variables(Extract search term)

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:

How to Track Site Search in Google Analytics 4 (3 Methods)

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:How to Track Site Search in Google Analytics 4 (3 Methods)

 

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:

How to Track Site Search in Google Analytics 4 (3 Methods)

Try to use the event names and event parameters in Enhanced Measurement Events.

Step 4 : Preview and Publish

Next is preview debugging.

How to Track Site Search in Google Analytics 4 (3 Methods)

Once validated, publish the GTM container.

Read More:

 

Method 3 : dataLayer.push (Best for SPA / Advanced Tracking)

For Single Page Applications (SPA) or websites where the URL does not change during search, neither Enhanced Measurement nor pageview-based triggers may work.

When to use it

Use this method if:

  • The page does not reload on search
  • URL remains unchanged
  • Search is handled via JavaScript frontend frameworks (React, Vue, Angular, etc.)

Implementation approach

Instead of relying on URL detection, push search events directly into the dataLayer。

Trigger event manually on search action,Push Event name: view_search_results,Parameter: search_term

This ensures accurate tracking even in fully dynamic applications.

Read More:GA4 Event Tracking Series ⑩ —— Custom Events (dataLayer.push Method)

 

How to 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.

 

Standard Reports (Limitations)

In the GA4 event report, you can see the view_search_results event:

How to Track Site Search in Google Analytics 4 (3 Methods)

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 「Create a detail reports」In「Library」,and make the following configuration:

  • Dimensions: Search term
  • Metrics: Event count
  • Report Filter: Event name Contains view_search_results

You can see the number of events for each search term in the canvas on the felt:

How to Track Site Search in Google Analytics 4 (3 Methods)

 

Explore (Advanced Analysis)

In GA4, click 「Explore」 —— 「Freeform」 and make the following configuration:

  • Dimensions: Search term
  • Metrics: 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:

How to Track Site Search in Google Analytics 4 (3 Methods)

Looker Studio

In Looker Studio, 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 left:

How to Track Site Search in Google Analytics 4 (3 Methods)

Common Issues & FAQ

 

Most search terms are blank

Cause:You are likely not filtering by view_search_results. Since other GA4 events do not include search_term, they appear as blank rows.

Fix:Always apply filter:event_name = view_search_results

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.

Like (5)
Post my comment
Cancel comment
Expression Bold Strikethrough Center Italic

Hi, you need to fill in your nickname and email!

  • Nickname (required)
  • Email (required)
  • Website