8-10 minutes
In this article, I am going to talk about setting up site search tracking in Google Analytics 4.
With the release of Google Analytics 4 property (GA4) in October 2020, by enabling enhanced measurement in GA4 you can automatically track and measure interactions and content on your sites in addition to standard page views.
Site search is also automatically tracked in GA4 property. Each time a user performs a site search, indicated by the presence of a URL query parameter an event is generated in GA4. You can see these events in real-time as below.
Site search events provide insight into the different user queries that users are looking at on the website. It also gives details about the results displayed to them.
By default, GA4 tracks the ‘view_search_results’ event when a user inputs a query and then click on the search button. As the event gets fired on the website, Google also sends a few default parameters such as search_term, page_location, and source. You can see these parameters in real-time.
Let’s set up site search tracking and understand it more.
Site search setup
Even though Site search setup is preconfigured in a GA4 property, if you want to know where the settings are configured you can follow the below steps.
Step 1: Navigate to Your GA4 Property in Google Analytics. Click on the ‘Admin’ tab available in the left-hand side reporting menu.
Step 2: A new overlay will appear, as below. Click on ‘Data Streams’.
Step 3: Data streams shows you all the available streams (GA4 properties and their details). Select the stream on which you want to set up site search tracking.
Step 4: An overlay will appear, like below, showing data stream details. It also shows details of enhanced measurement, which automatically tracks page views, scrolls, outbound clicks, file download, and site search. Click on the ‘Gear’ icon.
Step 5: Another overlay will appear like below, where you can see site search option is set to ‘Enabled’, like below.
If by any chance site search is not enabled, click on the toggle switch to turn it ‘On’.
Congratulations, you have successfully set up site search for Google Analytics 4!
Site search is automatically tracked, but it will only work on default query parameters defined by Google. A search query parameter is the part of the URL which comes after the ‘?’ character.
By default, the search event is triggered based on the presence of one of the following five parameters in the URL:
- q
- s
- search
- query
- keyword
If your website uses any other parameter, other than a default parameter, in its URL, you can additionally configure a custom parameter to fire the event.
Configuration custom search query parameter
Step 6: Click on ‘Show advanced settings’ under the ‘Site search’ option in ‘Enhanced Measurement’.
Step 7: An advanced settings panel will open up like below. In the ‘Additional Query Parameters’ text box type your custom query parameter that reflects in URL when someone searches. For example, I am using ‘searchid’ as the custom parameter.
Step 8: Click on ‘Save’ in the upper right corner of the overlay.
You are all set now. Head on to your website and perform any search query and you will see the search event firing in GA4 property in real-time.
Real-time debug
You can check in real-time for all the search events happening. To debug site search event tracking in real-time, follow below steps.
Step 1: Navigate to your GA4 property and click on ‘Realtime’ from the ‘Reporting’ menu.
Step 2: Now open a new tab in Chrome and navigate to your website. Once your website’s page has loaded completely, switch back to the earlier GA4 Chrome tab and you can see real-time events, like below.
Step 3: Now navigate to your website and perform any search query in the search box available. Let’s say I am searching for ‘Digital Marketing Blog’. Type the query in the search box and click on the search icon.
Step 4: You can now see the new page is being loaded, along with the search query parameter ‘searchid’ and our search text in the URL.
Step 5: Now switch back to your GA4 Chrome tab and check if the event is firing in real-time or not. As you can see from the below image ‘view_search_results’ is fired.
If you can see the ‘view_search_results’ event on the list, you have successfully set up the site search tracking.
Checking event parameters for site search events
Step 6: Now click on ‘All Events’ from the ‘Reporting’ menu on the left-hand side of the GA4 Chrome tab.
Step 7: You will see the event list as below. Click on the ‘view_search_results’ event.
Step 8: You will see in the ‘Reporting’ panel, a section with the title ‘Events in last 30 minutes’
Step 9: You will also see ‘Parameter name’ drop-down where you can find additional parameters. Click on the drop-down menu and you will get the list of parameters available along with events, as below.
Step 10: Select the parameter you want to see. For example, let’s select ‘search_term’.
Step 11: As you can see from the below image, the parameter value is ‘digital marketing blog’ for the parameter name ‘search_term’.
Step 12: If you want to check where this search was performed you can select ‘page_location’ parameter from the drop-down. Click on the drop-down again and select ‘page_location’.
Step 13: Once you select the page location parameter it will provide you with the details on where the search query was performed, as below.
So, that is how you can check events parameters for site search events.
Conclusion
Site search functionality provided by a website is widely used by users who are searching for information or products.
In order to know more about what type of queries users’ perform on the website, it always recommended to set up site search.
With a Google Analytics 4 property, you get site search tracking implemented by default. If by any chance it’s not enabled you can enable it through the ‘Enhanced Measurement’ option available for site search.
You can also configure your own search query parameter and fire the events.
In the Events report, in the GA4 ‘Reporting’ menu, you can also get more details on different event parameters when the search happens on the website.