Lesson 2 of 4
Site Search
① Connect your GTM container
Paste your container ID to load it into this page. It only ever runs here.
Advanced: use a specific environment
Site search is one of the most useful events to track, because it tells you in the visitors own words what they came looking for. GA4 has a built-in view_search_results event for exactly this, and the search_term parameter is what fills the Search terms report.
The form below pushes view_search_results with the query as search_term. Your job is a Custom Event trigger that listens for that event and a GA4 Event tag that forwards search_term along with it.
Goal
Catch view_search_results and fire a GA4 Event tag that maps the search_term parameter.
Build it in GTM
Capture the search term as a variable
The page pushes{ event: "view_search_results", search_term }. In Variables, under User-Defined Variables, click New, choose Data Layer Variable, set the Data Layer Variable Name tosearch_term, name itDLV - search_termand Save.Create the Custom Event trigger
Go to Triggers → New and choose Custom Event. In Event name typeview_search_results, matching the pushed string exactly, so the trigger fires on each search.Fire a GA4 Event tag that maps search_term
Create a GA4 Event tag with Event Nameview_search_results. Under Event Parameters, add a parameter namedsearch_termwith value{{DLV - search_term}}, then fire it on yourview_search_resultstrigger. For practice you can swap in a Custom HTML tag namedCustom HTML - Testwith<script></script>, but the GA4 Event tag is the real-site choice.
Debug in Tag Assistant
Copy this lesson's live URL and paste it into GTM Preview, that is the page Tag Assistant connects to. It has the clickable elements, so this page stays clean for reading.
- In your GTM, click Preview.
- Paste the live URL above and click Connect.
- Interact with the live page and watch your tag fire in Tag Assistant.
What you should expect to see
view_search_results event appears in the left rail, your tag shows under Tags Fired, and the outgoing hit carries search_term set to whatever you typed.Verify your container
Built it? Export your container, Admin → Export Container, choose your workspace, then drop the JSON here to check it against this lesson.
Drop your container .json here
or browse · checked in your browser, nothing is uploaded