Skip to content

Guide 149 · Events · GA4 + Tag Manager

Track site search with the recommended search event: search_term, the GA4 Event tag, and the empty-query trap

Checked 11 November 2026 · Verification: container fragment validated structurally (format 2, unique IDs, trigger resolves, variable references exist); worked example recomputed · Steps traced to Analytics Help and Tag Manager Help, opened 11 November 2026 · 6-minute read

The search box is where visitors say what they want in their own words, and GA4 only records it if the search event is sent with the search_term parameter. This guide builds search as a GA4 Event tag that fires on the submitted query, carrying the exact text typed, and checks it in DebugView before publishing.

Expected signal

After the tag is published, a test search shows in DebugView as a search event with search_term set to the query typed, and the Realtime report lists it under Event count by Event name within minutes.

Download the container fragment: the search event container fragment (JSON) (2311 bytes, MD5 a4dbd56c04e2a0bac42199fdf5fc623f). It holds one GA4 Event tag named GA4 - search, the Custom Event trigger that fires when the data layer event equals search, 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 search submit your site can signal. The push runs when the visitor submits the query, on the search results page or the submit handler — not on every keystroke.
  • The query text, exactly as typed. Google's prescribed parameter for search is search_term: the value is the term the user searched for.

The worked example

The test below is twelve searches in one day across four terms. The number that matters first is the total: twelve searches, with the most common term taking a third of them.

Search termSearches
refund policy4
shipping time3
gift card3
store hours2
Total searches12
Top term share4 of 12 (33.33%)
Average per term12 / 4 = 3.00

Those figures were recomputed here before publication: 4 plus 3 plus 3 plus 2 is 12; 4 divided by 12 is 0.3333, so the top term is 33.33% of the searches; 12 divided by 4 terms is 3.00 searches per term. The data layer push that carries one of those searches is the standard form:

dataLayer.push({
  event: "search",
  search_term: "refund policy"
});

The trace

  1. Push the search to the data layer on submit. When the visitor submits the query, run dataLayer.push({ event: "search", search_term: "refund policy" }), with the search_term value set to the query exactly as typed. The event name is search, exactly as Google spells it, and the parameter name is search_term.
  2. 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 variable DLV - search_term.
  3. Add the GA4 Event tag. Go to Tags, then click New. Name it GA4 - search. In Tag Configuration, choose tag type Google Analytics: GA4 Event. Enter your Measurement ID. In Event Name, enter search. Under Event Parameters, add a row with Parameter Name search_term and Value {{DLV - search_term}}.
  4. Set the trigger. In Triggering, click the trigger box and choose New, then choose trigger type Custom Event. Set Event Name to search and choose All Custom Events. Click Save, then Save the tag.
  5. Check it in Preview and DebugView. Click Preview, enter the site URL, and click Connect. Search for refund policy on the site. In Tag Assistant, the search event must appear in the left panel with the tag under Tags Fired. Then open DebugView (Admin, then Data display, then DebugView) and confirm the search event shows with search_term set to refund policy.
  6. 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 — THE TAG FIRES ON EVERY KEYSTROKE. A trigger on the search input counts typing, not searching. One visitor typing refund policy would record a dozen searches. The push belongs on the submit, where the query is final.

DEAD END — EMPTY QUERIES COUNT AS SEARCHES. A submit with an empty box sends search_term as an empty string, and the report gains a row that means nothing. Guard the push: send it only when the query has at least one character.

DEAD END — SEARCH_TERM WITH PERSONAL DATA IN IT. Visitors type names, emails, and order numbers into search boxes. A search_term that carries personal data breaks Google's terms. Check what the site does with the query before it reaches the tag, and never send a term that identifies a person.

End state

One tag, one trigger, one parameter. A search shows in DebugView within a minute of the test, in Realtime within minutes of publishing, and in the Events report within 24 hours, with the search_term list visible per row. The companion guide covers view_search_results: the event that records which results page the visitor landed on after the search.

Sources

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: 4 + 3 + 3 + 2 = 12 searches; 4 / 12 = 33.33% for the top term; 12 / 4 = 3.00 searches per term. Google moves menu items without warning; if a path on this page no longer matches, the linked help page is the current map.