Guide 150 · Events · GA4 + Tag Manager
Track search results pages with the view_search_results event: search_term, the GA4 Event tag, and the search-vs-results split
The search event records the query; view_search_results records the results page the visitor landed on. They are two different recommended events with the same search_term parameter, and mixing them up makes the search count and the results count the same number. This guide builds view_search_results as a GA4 Event tag on the results page load.
After the tag is published, a test search shows two events in DebugView: a search event on submit and a view_search_results event on the results page load, both carrying the same search_term.
Download the container fragment: the view_search_results event container fragment (JSON) (2376 bytes, MD5 1c8851b25a62f303a9b6f08ae8ccbf25). It holds one GA4 Event tag named GA4 - view_search_results, the Custom Event trigger that fires when the data layer event equals view_search_results, and the data layer variable for search_term. The Measurement ID is left as G-XXXXXXXXXX for you to replace. Import it from Admin, then Import Container, choosing Merge if the container already has tags.
What you need
- The Google tag already installed through Tag Manager. This guide adds one event tag beside it.
- A results page load your site can signal. The push runs when the search results page loads, carrying the query that produced those results.
- The query text, exactly as typed. The prescribed parameter for
view_search_resultsissearch_term, the same parameter thesearchevent carries.
The worked example
The test below is eight searches in one day and the results pages they produced. The split is the point of having two events: eight queries, eight result views, and three of the eight with no results at all.
| Measure | Count |
|---|---|
| search events (queries submitted) | 8 |
| view_search_results events (results pages loaded) | 8 |
| Result pages with zero results | 3 |
| Zero-result share | 3 of 8 (37.50%) |
| Result views per search | 8 / 8 = 1.00 |
Those figures were recomputed here before publication: 3 divided by 8 is 0.375, so 37.50% of the searches returned no results; 8 divided by 8 is 1.00 result views per search. The data layer push that carries one of those result views is the standard form:
dataLayer.push({
event: "view_search_results",
search_term: "gift card"
});
The trace
- Push the result view to the data layer on page load. When the search results page loads, run
dataLayer.push({ event: "view_search_results", search_term: "gift card" }), with the search_term value set to the query that produced the results. The event name isview_search_results, exactly as Google spells it. - Create the data layer variable. In Tag Manager, go to Variables, then in User-Defined Variables click New, choose Data Layer Variable, set the Data Layer Variable Name to
search_term, and name the variableDLV - search_term. If the search guide already created this variable, reuse it; do not create a second one with the same name. - Add the GA4 Event tag. Go to Tags, then click New. Name it
GA4 - view_search_results. In Tag Configuration, choose tag type Google Analytics: GA4 Event. Enter your Measurement ID. In Event Name, enterview_search_results. Under Event Parameters, add a row with Parameter Namesearch_termand Value{{DLV - search_term}}. - Set the trigger. In Triggering, click the trigger box and choose New, then choose trigger type Custom Event. Set Event Name to
view_search_resultsand choose All Custom Events. Click Save, then Save the tag. - Check it in Preview and DebugView. Click Preview, enter the site URL, and click Connect. Search for
gift cardon the site. In Tag Assistant, thesearchevent appears on submit and theview_search_resultsevent appears when the results page loads, each with its tag under Tags Fired. Then open DebugView (Admin, then Data display, then DebugView) and confirm both events show with the samesearch_term. - Publish it as a version. Click Submit at the top right, select Publish and Create Version, name the version, and click Publish.
Dead ends
DEAD END — ONE TAG FOR BOTH EVENTS. If the search tag and the view_search_results tag share a trigger, every query counts twice and the two rows in the report are identical. Two events, two tags, two triggers.
DEAD END — THE RESULTS PAGE ALSO FIRES SEARCH. A results page that runs the submit handler again on load sends a second search event for a query nobody typed again. The submit handler runs once, on submit; the results page runs only the view_search_results push.
DEAD END — ZERO-RESULT SEARCHES NEVER REACH THE TAG. If the site shows a "no results" page without running the results push, the zero-result searches vanish from the report and the site looks better than it is. The push runs on every results page load, including the empty one — that is the row that tells you what visitors cannot find.
End state
Two tags, two triggers, one shared parameter. A search shows a search event and a view_search_results event in DebugView, one per step of the same action, both carrying the same search_term. In the Events report the two rows sit side by side: the gap between them is the share of queries that never reached a results page, and the zero-result share is the list of terms the site fails to answer.
Sources
- Analytics Help — [GA4] Recommended events — search is a recommended event for all properties; the results view is its companion event
- Google Analytics developer documentation — GA4 event reference — the view_search_results event and its prescribed parameter, search_term
- Tag Manager Help — Set up Google Analytics events in Tag Manager — the GA4 Event tag, the Measurement ID, the event name, the trigger, and Preview verification
- Analytics Help — Monitor events in DebugView — Admin, then Data display, then DebugView
Checked 11 November 2026. The click paths above are the ones in Google's help and developer pages, opened 11 November 2026. No step in this guide was run inside a live Analytics property or a live Tag Manager container, because both need a Google sign-in and this site does not sign in as anyone. What was run: the container fragment was validated structurally in Python 3.12.3 — export format version 2, unique IDs, the tag's firing trigger resolves to the Custom Event trigger in the file, and the {{DLV - search_term}} reference exists as a variable — and the worked example was recomputed: 3 / 8 = 37.50% zero-result share, 8 / 8 = 1.00 result views per search. Google moves menu items without warning; if a path on this page no longer matches, the linked help page is the current map.