Back in March, we covered how you can set up site search tracking in Google Analytics 4. Here, we are going to look at how you can expose and view the search terms in regular reporting widgets, not just via real-time reporting.
When you set up site search tracking and then perform a search, you’ll see the event come through as a view_search_results event in the ENGAGEMENT > EVENTS report:
But clicking on this to view further details, will only show you a widget containing the list of terms searched in the last 30 minutes. What if you want to see historical data? As we’ve mentioned before, GA4 takes a bit more customisation work than Universal Analytics to get the data that you want, displayed in the right place.
To do this and expose the site search parameter you’ll need to create the event as a custom dimension first.
Exposing Site Search Terms in GA4
To do this:
- Select CONFIGURE from the menu on the left-hand side of any Google Analytics page:
…then, select CUSTOM DEFINITIONS on the secondary navigation pane:
2. Select CREATE CUSTOM DIMENSION:
3. In the NEW CUSTOM DIMENSION boxes you’ll find fields for:
- Dimension Name: The name that will appear in your search term widget (report table)
- Scope: Specifies to which data the custom dimension or metric will be applied.
- Description (optional): Free text to describe your dimension further
- Event parameter: The event parameter you want to be exposed in reports



While the dimension name and description are free text boxes, you’ll need to select Scope and Event parameters from a pre-defined list. When tracking site searches the Scope should be set to ‘Event’ and the Event parameter should be set to ‘search_term’ as your objective is to pull through the value of the search term parameter.
search_term is the parameter pulled through on the view_search_results event which is triggered when a user searches your content.
4. Once that’s done, go back to REPORTS > ENGAGEMENT > EVENTS.
Then, in the table select view_search_results:
5. On the next page, you should now see the event name you selected (in the drop-down box) and a widget that corresponds to the custom dimension name you used to create the search_term dimension:



It is there that you will now see a list of the search terms that people have used to search your site!
It still does not work – shows empty container – do we have to set a tag in GTM for this?
dataLayer.push({
‘event’: ‘view_search_results’,
‘search_term’: {heavy duty, how to repair a slide,
}
});
also what is the difference between search & view_search_results
what will happen to this datalayer which defined by google for search?
dataLayer.push({
‘event’: ‘search’,
‘search_term’: {heavy duty, how to repair a slide,
}
});
Do I have place a new datalayer for this to work?
dataLayer.push({
‘event’: ‘view_search_results’,
‘search_term’: {heavy duty, how to repair a slide,
}
});
also what is the difference between search & view_search_results
and what will happen to this datalayer which defined by google for search? this one also doesn’t show the search terms in GA4
dataLayer.push({
‘event’: ‘search’,
‘search_term’: {heavy duty, how to repair a slide,
}
});
Hi Humaira,
You shouldn’t need to use the data layer if the search term is passed through in the URL when a user performs a search on your site.
You just need to follow setting up site search under Enhanced Measurement first- the blog below has steps on how to do this:
https://www.glowmetrics.com/blog/setting-up-site-search-in-ga4/
Then, you follow the steps above to expose the site search terms via a custom dimension to view this in the event report.
Joanne
followed both of your blog now – placed the custom definitions as well, paused the search tag in tag-manager
now it does not show search_term in 30 min window
/search?keyword=hello
placed keyword and search under admin/site search
Am i doing something wrong?
Hi Humaira,
You should be able to see the event parameter view_search_results in realtime reports when a search has taken place.
Under Engagement > Events, within this table you should also be able to see the event for view_search_results and if you click that, you should be able to see the SITE SEARCH QUERY within a widget there.
If you are still having issues, feel free to email me directly on joanne[at]glowmetrics.com and I can take a look at your set-up.
Joanne
That would be great – I have dropped you an email
Kind regards
Humaira