If your website has a search feature, it is crucial to understand what your visitors are looking for, and in this blog, we'll show you how to track site search with google analytics 4. And, no, just enabling site search in enhanced measurement is not enough.
Suppose you want to stay up to date with google analytics 4. In that case, you need to understand that google analytics 4 can automatically track a bunch of interactions like file downloads, outbound link clicks, and so on. Site search is also on that list, but if you want to start seeing that data in your GA-4 reports, you have to do some additional configuration, and here, you'll learn the exact steps.
So, let's dive in here, get onto your website or any demo website and install a demo google tag manager container on it. Also, have one tag, which is a GA-4 configuration tag, because that is the bare minimum that you have to do in order to install google analytics on your website with google tag manager.
Now, in your google analytics 4 property, you have to configure a data stream so it enables enhanced measurement. One of the interactions that are enabled is site search on many websites; this feature is enough to start tracking site search queries with google analytics 4.
Let's understand how this functionality works in action; suppose we are looking for t-shirts. Hence, we will use the site search; what's most important here is that we have a query parameter which is 'q', and this is the actual keyword that we will be entering in the search field since we have this combination- google enhanced analytics measurement should be able to catch this search because, in the URL, we have the search parameter like this.
In order to start seeing this information in the debug view of google analytics 4, we have to either enable the preview mode in google tag manager or enable the GA debugger chrome extension in order to start seeing the data right. So, all you have to do is just enable the preview mode and enter the URL of your website and then enter the search query once again, which was a t-shirt.
The actual principle of how this automatic search tracking works every time a page reloads google analytics for tracking code is looking for certain URL parameters that might be related to the search query. In this case, we have a parameter called 'q,' but there are also some other parameters that google analytics 4 recognizes as well. If we go to google analytics admin, then select > data stream, then click on the gear icon > click show advanced settings under the site search feature.
There, you will find a list of five default query parameters that google analytics 4 recognizes. We have a 'q' search query and keyword. They are all separated with a comma if your website is using some different query parameter, for example, search key or something like that- you can see this parameter is not included right here, but you can edit it and include your own parameter like this. However, it looks like the GA-4 site search feature does not like when you add something besides words and commas. Therefore, if your parameter includes the dash (-), it will not work, but if your parameter was like a search key, then you could enter it, and it would work just fine.
Hence, if a page loads and google analytics 4 loads, and if in the URL, there is a certain query parameter that contains the search keyword that the user entered in the search field. Then you can configure site search to take that parameter. The value of this parameter will be sent as an additional parameter search term with the event that is sent to google analytics 4. All of this is done with the help of enhanced measurement in google analytics 4.
On most websites, these five parameter names are usually sufficient, but if you are working with some custom website or your website is using a different parameter, then make sure to include a new parameter by clicking save.
From that moment, you will be able to use this parameter in things like analysis hub or some other reports in google analytics for a long time. Keep in mind that in order to start actually seeing this parameter in reports, you will have to wait for up to 24 hours.
Now, it's time to look into how to create the report in google analytics. Let's say you're using the analysis hub, which you can find under the 'analysis section,' and here you can click on 'exploration' in the dimension. By clicking on the plus and including a new dimension which is the search term, click 'apply,' and then drag this dimension over the existing dimension in the rows section.
And if you did not manage to remove it, then you should just remove the previous dimension and make sure that you have only the search term in the rows section, and then you can clear the columns and remove the active users metric in the value section.
So, in total, what you'll have here is the dimension search term which is added to the rows block right and then no dimensions in the column, and then an event count metric in the values section. In total, what you'll remain with the bunch of not set event values.
Remember, if you want to start seeing search term parameters and use them in the reports of google analytics 4, then you have to register this parameter as a custom dimension. It is the first thing; then you will have to wait for up to 24 hours to start seeing this parameter in the reports and being able to include it as a dimension and then if you want to use some other things like event count or event name dimension in the filters section.
You have to make sure that those things, for example, let's imagine that your search feature on the website has not only the search field but also some advanced filtering capabilities- something where you can select gender, product, type, body fit, or something else. So if those additional parameters of the search are also visible in the URL of the search results page, you can configure enhanced measurement to take that automatically. So let's assume that you have entered a keyword pan but also have selected a checkbox that says that you're interested only in mail pans, and then in the URL of the search results page, the parameter was added.
For enhanced measurement, what you could do is you could go to the data stream settings, then to enhance the measurement settings, and then click show advanced settings under site search.
If this tracking method did not work for you because maybe your search results URL actually contains a hashtag. So, in a nutshell, what you will have to do is that you will have to manually send the view search results event with some additional parameters to google analytics 4, and this is how you track site searches with google analytics 4.
Remember, if you want to see the data in your GA-4 report, you will also have to register custom dimensions for it. Hopefully, this will be done automatically in the future, but we have to manually configure the dimension. If the URL of the search results page does not contain any query parameter with the search key, you can manually send the search event to GA4 together with the actual search keyword.