
April 1, 2025
Track Site Search with Google Analytics 4 (GA4 Site Search)
Updated: April 1st, 2025
Site search tracking has always been a hidden gem for me when analyzing visitors’ behavior on a site. Why? Because you can quickly identify what your visitors are looking for on your site and whether you have to offer something relevant.
Google Analytics 4 Enhanced Measurement can automatically track search queries (at least in most situations), but to see that data in reports, you have to do some additional configuration. Also, if your website’s search works differently than GA4 expects it to, then you will have to do some additional configurations in Google Tag Manager). In this blog post, I’ll cover various options how to track site search with Google Analytics 4 and (if needed) with Google Tag Manager.
The tracking method depends on how the site search is implemented on your site.
Table of Contents
Here’s what you will learn in this article
- What is GA4 site search tracking?
- Why are Site Search Reports valuable?
- Automatic search tracking
- What if standard site search tracking in GA4 does not work?
- Where to find Search Terms in GA4?
- Other Site Search Tracking Methods
- (Optional) Register Custom Dimensions
- Search with zero results
- Final Words
Video tutorial
If you prefer video content, here’s a tutorial on my YouTube channel. If that method does not work, come to this blog post for alternative options.
How to read this guide
This blog post is quite lengthy, so here are my tips on how to get the most out of it in the least amount of time:
- First, I will present the most basic site search tracking option: a built-in feature of GA4
- Then I will explain how to create a Search Terms report in Google Analytics 4 explorations.
- If the built-in option does not work, I will share 4 more setup methods
- Then, I will explain how to register custom dimensions related to the site search in GA4 (this is optional)
What is GA4 site search tracking?
It’s a feature that lets you see (in a nice, clean table) what keywords people enter in your website’s search field.
And the best part is that Google Analytics 4 (in many cases) can track this automatically. There are some caveats/limitations, but don’t worry. I will share solutions later in this article.
Why are Site Search Reports valuable?
In my opinion, site search data is a goldmine.
Your clients/visitors are directly telling you what they are looking for. By collecting site search data, you will see which keywords are more popular/in demand. You might also find out that people are looking for something specific that your website/company does not offer yet. That’s a business opportunity!
Here’s a sample search report from my blog.
And here are the ways how I make this table useful:
#1. I check whether the search is showing relevant results to my visitors. I pick the most popular queries, enter them on my site, and check what the internal search returns.
- Are the top results relevant?
- Are there any non-sense results? Maybe the search also returns some hidden pages that shouldn’t appear there, etc.
Checking search queries in such a way is very time-consuming and tedious. However, it’s a good way to evaluate whether the search is actually working correctly on your site.
If you indeed have content related to the keyword X, but it was not displayed in the results, you could talk to developers about how to improve this. If you are using a popular content management system (like WordPress), you could try to find a better-performing search plugin.
#2. I find new ideas for content. While you can do keyword research with tools like Google Search Console, Ahrefs, etc., your own site search is a gold mine too. If many visitors have landed on your site and are looking for X (and you don’t have that type of content), maybe it’s time to create one.
While it’s fairly difficult to aggregate the data (because people can look for the same thing while using different keywords), you can still get a sense of what your visitors are interested in.
What do I mean by saying, “use different keywords to find the same thing”? For example, 5 people might be looking for a GA4 ecommerce guide but their search terms might look like this:
- google analytics ecommerce
- ga4 ecommerce
- e-commerce ga4
- gtm ga ecommerce
So, how can we track site search with Google Analytics 4? The answer is the classic “it depends”. It depends on how the site search is coded on your site and how it works.

Automatic search tracking (with GA4 Enhanced Measurement)
This option is the easiest one (and does not require Google Tag Manager at all). Try to use your website’s search feature. Enter any word in the search field and hit the Search button.
Did the page reload and the URL change?
If yes, is the search term displayed after the question mark? Does it look similar to this yoursite.com/?search=my+keyword? Or maybe like this yoursite.com/?s=my+keyword?
If the answer is yes, you’re lucky. If the search query is displayed in the URL after the question mark (but not after the #), this means that your search is working with query parameters. In my first example (yoursite.com/?search=my+keyword), the query parameter for the search term is search. In the second example, it is s.
Now, go to your Google Analytics 4 property > Admin (click the gear icon in the lower-left corner) > Data Stream > Select your web stream and make sure that Enhanced Measurement is enabled.
If yes, then click the gear icon and then Show Advanced Settings under the Site Search section. Here you will see 5 default query parameters that Google Analytics 4 recognizes: q, s, keyword, search, query. If your website is using a different query parameter in the URL to store the search keyword, enter that parameter. You can have up to 10 parameters in total (separated by a comma).
Save the changes.
#1.1. Time to test
Now, you will have to enable the DebugView in GA4 (I mean, make the data visible here). There are several options for it, but now you can either enable the GTM preview mode or enable the GA Debugger Chrome extension.
Once you do that, then go to your website, enter a word in the site search field, and hit enter. You will be redirected to the search results page, and in the URL, you will see your search term as one of the URL parameters (a.k.a. query parameters).
Now, go to the DebugView of GA4, and soon you should see an event called view_search_results. This was automatically sent by enhanced measurement. If you cannot see any data in DebugView, read this blog post.
Click the view_search_results event and then click the search_term parameter. It should contain the word(s) that you entered in the site search field.
So, if everything looks good, let’s look at where you can find this data in other GA4 reports.

#1.2. What if your site search offers advanced filters/options?
On some websites, the search feature consists of more than just the search field. There might be additional filters/features that can help users narrow down their search. If we talk, for example, about an apparel ecommerce website, additional filters can be size, gender, brand, etc.
If these additional parameters are also visible in the URL as query parameters, you can enter them in the Enhanced Measurement settings, and GA4 will handle that automatically.
Let’s say that I used the site search feature and entered the keyword pants. Also, I have selected “male” in the gender field. Consequently, the URL of the search results page looks like this: https://example.com/search/?q=pants&gender=male.
Let’s go to your Google Analytics 4 property > Admin > Data Streams and select your data stream. Then click the gear icon in the “Enhanced Measurement” section and then Show Advanced Settings under Site Search.
In the Additional Query Parameters field, enter gender. If the URL contains more parameters and you want to track them too, enter all of them (separated by a comma).
Save the changes. Then go to your website and perform a new search with the gender field selected as well. In the DebugView of GA4, you will see a new view_search_results event. Click it.
With the search_term parameter, you will see a new parameter, q_gender. This was automatically tracked by enhanced measurement. If you configured a different parameter (e.g. brand), then the parameter’s name will be q_brand.
That’s awesome, right? After you configure this successfully, jump to this article section, where I explain how to register custom dimensions. Every custom parameter that you want to see/use in GA4 reports will have to be registered in GA4 as a custom dimension.
What to do if the standard site search tracking in GA4 does not work?
Don’t worry. I explain a bunch of other methods later in this blog post. They will involve Google Tag Manager. You can skip to it by clicking this link. But first, let’s look at the reports.

Where to find Search Terms in Google Analytics 4
There are several options. If you want to learn more about where to find site search data in GA4, read this article too. Important: it takes 24-48 hours for GA4 to start showing newly collected data.
Also, you can take a look at this video tutorial:
#1. Events
The most basic report is available in Reports > Engagement > Events > view_search_results, and then you will find a widget with the more popular search terms (or, you can also go to Reports > Engagement > Events > view_search_results).
Important: This widget will become available only after registering search_term as a custom dimension.
Note: The GA4 sidebar is highly customizable. The location of the “Events” report in your property might differ, so keep looking.
But I am not a fan of this way. So, your second option would be a customized standard report.
#2. Customized standard report
You must have enough permissions in your GA4 property to pull this off.
In Google Analytics, go to Reports > Engagement > Events. Click the Pencil icon in the top-right corner. Don’t worry. We will not overwrite the changes in this report.
Click Dimensions, and remove Event Name.
Then, add a Search Term dimension and hit Apply.
Then go to Metrics, and keep “Event count”, “Users”, “Event count per active user” metrics. Apply.
Finally, let’s add a filter to include only view_search_results events. In the “Report filter” section, enter the following condition:
If necessary, you can hide unwanted charts (e.g., Bar Chart). Apply all changes. The report will look like this:
Then click Save > Save as a new report. Give it a name, e.g., Site Search Terms, and click Save. The final step is to publish this report and add it to the left sidebar.
Go back to the “Reports” of Google Analytics 4, select any report, and then click Library.
Then, find the Life Cycle collection and click Edit collection.
From the column on the right, drag the Site Search report to the Engagement section. Click Save > Save changes to the current collection.
Done! The Site Search report is now available to every user of the GA4 property. They will find it in Reports > Engagement > Site Search.
#3. Free Form Exploration
One more option is to use the Explore section. In Google Analytics 4, go to Explore > Free Form
Here, you will find 3 columns:
- Variables
- Tab Settings
- and the actual output of the report.
In the Variables column, click the Plus icon in the Dimensions section and find search_term. Select it and click Apply.
Then drag search_term dimension to the Rows section. Remove any other dimensions that are in the Rows section. Clear any dimensions in the Columns section.
Then, in the Values section, add the Event Count metric (drag it from the Metrics section).
In the Filters section, enter the following condition: Event Name exactly matches view_search_results.
Done! You will now see the report, and if you wish, you can add some additional metrics/dimensions/segments.
Also, you can change the date range in the top-left corner of the exploration.
Other Site Search Tracking Methods
If GA4’s built-in site search tracking (in Enhanced Measurement) does not work on your website, you will need to create a custom solution. Below, I listed several of them so check which one fits your needs.
#1. Track site search without query parameters
Another example of how a search query can be displayed in the URL is yoursite.com/search/search+query.
In this case, the search term is not a query parameter. Therefore, the built-in GA4 functionality will not be able to capture it. That’s where Google Tag Manager becomes handy.
There are many ways how to skin a cat in this type of situation, but I’ll show you one of the possible ways. Here’s the plan:
- We will extract the search term from the URL
- We will manually send the view_search_results event (with GTM). That event will also include a parameter called search_term.
#1.1. Custom JavaScript Variable
The first two steps will be done with a little Custom JavaScript variable named cjs – search query. Here’s the code:
function() { var pagePath = window.location.pathname; var searchParam = '/search/'; //replace this with your page path before the search term if (pagePath.indexOf(searchParam) > -1) { return decodeURI(pagePath.split(searchParam)[1].split('/')[0]) } }
On line 3, you need to enter what the Page Path of your URL looks like before the search term. Let me illustrate.
- If your search URL is yoursite.com/search/your-search-term, you need to enter /search/ in the Custom JS variable (together with the opening and closing slash.
- If your search URL is yoursite.com/search/results/your-search-term/, you need to enter /search/results/
If the Page Path does not contain the searchParam that you have defined, then this Custom JS variable will return undefined.
#1.2. Create a Google Analytics 4 tag
Let’s send the value of our Custom JavaScript variable to Google Analytics 4 (together with a view_search_results event). Go to Google Tag Manager > Tags > New > Google Analytics 4 event.
In the first field, enter the measurement ID of your data stream. Personally, I recommend creating a Constant Variable that contains the measurement ID and then use that in the field. It will make your tag management easier (learn more here).
In the Event name field, enter view_search_results. Then click Event Parameters and enter search_term. In the value field of that parameter, insert the Custom JavaScript variable you created in the previous chapter.
In the triggering section, click anywhere on the white space and then click the Plus icon in the top right corner to create a new trigger.
The trigger should use the following settings:
- Type – Page View
- This trigger fires on – Some Page Views
- Enter the following condition: cjs – search query (that’s your Custom JS variable) does not match regex (ignore case) ^(undefined|null|0|false|NaN|)$
This trigger will fire if the pageview occurs and the page URL contains the search query.
Save the trigger and then save the tag.
#1.3. Test
First, let’s test with the GTM preview mode. Click the Preview button in GTM’s interface, then enter the URL of your search results page. After you are redirected to the search page, return to the Preview mode’s page and click the most recent Container Loaded event. There you should see the GA4 event tag fired.
If yes, let’s test whether the data to Google Analytics was sent properly.
Go to GA4 DebugView. If needed, find your device (in the top left corner of the DebugView) and then check if you see the view_search_results page appear in the event stream. If yes, click it and check if the value of the search_term parameter is correct.
After you configure this successfully, read this article on how to see search term data in GA4 reports. Important: the data will appear in reports within 24-48 hours.
#2. Track auto-complete search
This method is an advanced one.
Some websites use auto-complete search functionality (when you start typing a search term, and the results start to show up after a couple (or so) seconds.
In a nutshell, here’s the process of how things will work:
- A visitor starts typing a search query in the search field
- If he/she pauses or stops for a couple of seconds, a virtual pageview is sent to Google Analytics together with a modified page field (just like we did in chapter #2).
This option/solution is offered by Simo Ahava, but I have adapted it to Google Analytics 4.
#2.1. Custom HTML tag (listener)
Go to Google Tag Manager > Tags > New > Custom HTML and paste the following code:
In the triggering section, create a new trigger called DOM Ready. If the search field is on every page, you can set the trigger to fire on All DOM ready events. Otherwise, you can make it more precise (e.g., fire only on certain pages where it is possible to use the site search).
IMPORTANT: this code will not work out of the box. You must modify it (at least line 6 with var searchField). Read this guide for further instructions. And when you’re done editing the code, come back here.
#2.2. Data Layer Variable and Custom Event Trigger
When the aforementioned Custom HTML tag is activated, it starts looking for interactions with the autocomplete search field on your website. If that happens, then the search data is pushed to the Data Layer. If we want to use that data, we must create a Data Layer Variable and a Custom Event Trigger.
In GTM, go to Variables > New > Data Layer Variable and enter the following settings:
Important: the name of the variable must be exactly customSearchInput (case-sensitive).
Then go to Triggers > New > Custom Event trigger and enter the following settings:
Here the event name must be precisely customSearch.
Save everything.
#2.3. Google Analytics 4 event tag
In Google Tag Manager, go to Tags > New > GA4 Event tag and enter the following settings:
- Event name: view_search_results
- Parameter name: search_term, value: the Data Layer Variable that you have just created.
- Trigger: The Custom Event trigger that you created above.
Save the tag.
#2.4. Test
First, let’s test with the GTM preview mode. Click the Preview button in GTM’s interface, then enter the URL of your website. After you are redirected to the search page, enter something in the search field. Come back to the Preview mode page, and you should see the customSearch event on the left side of the preview mode. Click it. There you should see the GA4 event tag fired.
If yes, let’s test whether the data to Google Analytics was sent properly.
Go to GA4 DebugView. If needed, find your device (in the top left corner of the DebugView) and then check if you see the view_search_results page appear in the event stream. If yes, click it and check if the value of the search_term parameter is correct.
After you configure this successfully, read this article on how to see search term data in GA4 reports. Important: the data will appear in reports within 24-48 hours.

#3. Track site search with the developer’s help
If none of the abovementioned site search tracking options work for you, this means that:
- The URL of the search page does not contain the search term at all
- Your search is not based on auto-complete
In that case, your plan B is to ask for a developer’s help. You could ask him/her to push the search term to the Data Layer every time a visitor completes a search.
Here’s a sample dataLayer.push code that a developer should incorporate somewhere in his code:
#3.1. A trigger and a variable
After a developer implements this code, we need to create a Custom Event Trigger for search and a Data Layer Variable for searchTerm.
In GTM, go to Triggers > New > Trigger Configuration > Custom and enter the following settings:
Save the trigger. Then go to Variables > User-defined Variables > New > Data Layer Variable and enter the following settings:
#3.2. Google Analytics 4 event tag
Go to Tags > New > GA4 event tag and enter the following settings:
- I inserted the measurement ID with a constant variable
- Event name: view_search_results
- Parameter name: search_term, value: the Data Layer Variable you created.
- Trigger: The Custom Event trigger that you created above.
#3.3. Test
First, let’s test with the GTM preview mode. Click the Preview button in GTM’s interface, then enter the URL of your website. After you are redirected to the search page, enter something in the search field. Come back to the Preview mode’s page and you should see the search event on the left side of the preview mode. Click it. There, you should see the GA4 event tag fired.
If yes, let’s test whether the data to Google Analytics was sent properly.
Go to GA4 DebugView. If needed, find your device (in the top left corner of the DebugView) and then check if you see the view_search_results page appear in the event stream. If yes, click it and check if the value of the search_term parameter is correct.
After you configure this successfully, read this article on how to see search term data in GA4 reports. Important: the data will appear in reports within 24-48 hours.
#4. Track site search with DOM scraping
The final option of this guide is the riskiest one. You should try it ONLY if the other options mentioned in this article do not work.
Important: This is just an example. Your case might look different. Therefore, you might need to adapt my solution.
In this chapter, I will show you a hypothetical situation where:
- Page URL does not contain the search term
- The search is not auto-complete
- A developer is not available
- BUT the search term is displayed on a page (e.g., as Heading 1). Like in the example below:
After I enter the search keyword, it is displayed at the top of the screen (surrounded by quotation marks). If I right-click on that search term, I’ll find out that the entire Search: “sample page” is a single element h1.
Therefore, I will need to extract it and then strip all of the unnecessary parts.
Caveat: in my case, this solution will only work if visitors DO NOT translate my website. If they do, then “Search:” will also be translated to something different. Therefore, the CJS variable will not work.
#4.1. A variable that returns the search page’s H1
First, let’s create a GTM variable that will pick the entire h1’s value. My hypothesis is that the element h1 with class archive-title is the only element on a page, and using the CSS Selector h1.archive-title should be enough to pick that element (because if not, we will need to come up with a more specific way to pick that element).
To check that, open your browser’s JavaScript console and enter the command document.querySelectorAll(‘h1.archive-title’) and hit ENTER.
P.S. You will most likely see different CSS classes on your website. Therefore, you will need to come up with a different selector. If you have no idea what is going on, consider joining my Intermediate/Advanced Google Tag Manager course.
Back to the JS console. How many results do you see there? If one, that’s good. If many, then you need to be more precise and update your selector.
In my case, I was lucky, and the h1.archive-title CSS Selector returned only one element on a page.
In GTM, go to Variables > New > DOM Element and enter the following settings:
Save the variable and enable the preview mode. Refresh the page with the search results and click on the DOM Ready event. Check the value of your DOM Ready variable. If it’s null, check whether you configured the settings of the variable exactly as I did.
#4.2. A variable that extracts the Search Query
In my example, the DOM Element Variable returns the Search: “sample page”. I need to get rid of Search: “ in the beginning and ” at the end.
Let’s create a Custom JS variable for that. I’ll show you everything step by step:
First, let’s create an anonymous function:
function() { }
Then, let’s define the variable that will return the h1 (of our search page). This is not necessary, but since I will be referring to it multiple times, that’s more convenient:
function() { var searchTitle = {{DOM - h1.archive-title}}; }
See that thing surrounded by {{ }}? That’s our DOM variable from the previous chapter. If you named it in a different way, then make sure you enter the correct name in the Custom JS variable’s code, too.
Now, let’s make sure that this Custom JS variable returns the search query only if the DOM element actually contains “Search:”. We can do that with an IF statement.
function() { var searchTitle = {{DOM - h1.archive-title}}; if (searchTitle && searchTitle.indexOf('Search:') > -1) { // something will happen } }
If the Page Title (h1) does not contain “Search:”, then the variable will return undefined.
Then, let’s extract the actual search term from the Search: “sample page”. We are interested only in the sample page. There are many ways to achieve this, and I’m pretty sure the mine is not optimal, but it still does the job.
First, let’s get rid of the Search: “ . I use replace() method for that where I locate Search: “ and replace it with nothing.
function() { var searchTitle = {{DOM - h1.archive-title}}; if (searchTitle && searchTitle.indexOf('Search:') > -1) { var searchQuery = searchTitle.replace('Search: “',''); } }
After this is implemented, our CJS variable will return sample page” instead of Search: “sample page” but there’s still the quotation mark at the end. Let’s add one more replace().
function() { var searchTitle = {{DOM - h1.archive-title}}; if (searchTitle && searchTitle.indexOf('Search:') > -1) { var searchQuery = searchTitle.replace('Search: “','').replace('”',''); } }
Finally, our Custom JS variable should return the new (fake) page path together with a search query parameter. If the search term consists of multiple words, the spaces between them will be encoded (thanks to the encodeURI method).
function() { var searchTitle = {{DOM - h1.archive-title}}; if (searchTitle && searchTitle.indexOf('Search:') > -1) { return searchTitle.replace('Search: “','').replace('”',''); } }
Now go to Variables > New > Custom JavaScript Variable and paste the abovementioned code. Name the variable cjs – search query.
If the H1 of the search page is Search: “google tag manager”, this Custom JavaScript variable will return google tag manager.
#4.3. Trigger
Let’s create a trigger that is fired when the aforementioned Custom JavaScript variable contains some value (in other words, when the search keyword element is visible).
In Google Tag Manager, go to Triggers > New > DOM Ready. Enter the following settings:
- Some DOM Ready events
- {{cjs – search query}} does not match regex (ignore case) ^(undefined|null|0|false|NaN|)$
{{cjs – search query}} is the name of the Custom JS variable that you have just created. It might be different in your case.
#4.4. Create a GA4 event tag
Go to Tags > New > GA4 event tag and enter the following settings:
- Event name: view_search_results
- Parameter name: search_term, value: the Custom JavaScript Variable that you have just created.
- Trigger: The DOM Ready trigger that you created above.
Caveat: in my case, this solution will only work if visitors DO NOT translate my website. If they do, then “Search:” will also be translated to something different. Therefore, the CJS variable will not work.
#4.5. Test
First, let’s test with the GTM preview mode. Click the Preview button in GTM’s interface, then enter the URL of your search results page. After you are redirected, go back to the Preview mode’s page and click the most recent DOM Ready event on the left side of the preview mode. There you should see the GA4 event tag fired.
If yes, let’s test whether the data to Google Analytics was sent properly.
Go to GA4 DebugView. If needed, find your device (in the top left corner of the DebugView) and then check if you see the view_search_results page appear in the event stream. If yes, click it and check if the value of the search_term parameter is correct.
After you configure this successfully, read this article on how to see search term data in GA4 reports. Important: the data will appear in reports within 24-48 hours.
(Optional) Register Custom Dimensions in Google Analytics 4
Depending on your needs, you might have to register search_term as a custom dimension in Google Analytics 4 (in order to see it in the reports).
If you care only about custom reports (a.k.a. explorations) or standard reports, then you DON’T need to register a custom dimension. Just read this guide on how to build the report.
But if you want to use/view search_term in Reports > Engagement > Events > view_search_results, then you will need to register an event-scoped custom dimension.
To do that, go to Admin > Custom Definitions.
Click Create custom dimensions and enter the following settings:
- Dimension name means the label of the dimension you will see in the reports. It can be a Site Search Term, search_term, or anything else.
- Scope – select Event
- Description. You can leave this field empty. This is a description for internal use.
- Event Parameter – here, you must enter exactly search_term (it’s the parameter name that is sent with every view_search_results event)
If you are tracking more parameters (for example, q_gender from tracking option #1), you should register them too. Create all needed dimensions one by one and save them. After ~24-48 hours, you will start seeing/using custom dimension(s) in your reports.
Note: custom dimensions are not retroactive. If you sent the search_term parameter for 1 week and only then created a custom dimension in the GA4 interface, your reports will show data only from that moment when you registered a custom dimension. So, you should do that as soon as possible.
Search with zero results
What if your visitor sees something like this when he/she enters a search term?
Let’s send an event to GA whenever this happens. First, we need to inspect that error message. In my case, it’s a div with class is archive-subtitle.
Let’s create a DOM element variable with the following CSS Selector div.archive-subtitle. Now, let’s create a trigger with the following settings:
By the way, the caveat here is the same as in tracking method #5. If a visitor translates the page, this zero-search-results tracking will not work. Therefore, it is highly recommended to implement this with the help of a developer (and ask him/her to push the data to the data layer). Or try to find some other method, not DOM Scraping.
Back to the topic. Create a trigger that will be activated if the subtitle DOM element contains the words We could not find any results for your search.
Finally, let’s create a GA4 Event tag with the following settings:
Assign the previously created DOM Ready trigger to this GA Event tag.
With it, we will send the search query that returned 0 searches and will be able to quickly identify which search terms are worth our time to invest.
I talk more about this in my YouTube tutorial:
Track Site Search with Google Analytics 4 and GTM: Final Words
Hopefully, this guide will help you solve most of your challenges related to site search tracking with Google Analytics 4. Most often (based on my experience), you will deal with the regular search + query parameter and a search without query parameter (while the search term is still visible in the URL). In that case, the Enhanced Measurement in GA4 should handle it without problems.
Got any other questions? Let me know.
70 COMMENTS
Hi Julius!
I am working on an ionic framework to build a hybrid application. I have integrated google tag manager also.
When I run the application in the desktop browser, I can see the relevant data flowing into the UI of google analytics. But, when the application is opened in mobile using APK, I don't see data reflecting on google analytics end.
Hi, not enough information. Please provide more. Check whether your does not behave differently on mobile devices.
Nice article Julius, really covers a wide scope of scenario a measurement marketer can be faced with, but will love to throw in another option for non technical and people, in the part of the article that talks about don scraping the search term, non technical marketers can just push in that query that way into GA and the. Clean em up with filters, though this is not recommended, because it doesn't make the search variables reusable in other analytics tools like amplitude, Mixpanel, FB analytics, etc.
Once again, thanks Julius
Hi, please read chapter 2.1. It explains what needs to be changed.
It amazes me the number of Google Analytics audits we do where someone has taken the time and effort to setup site search and then forgets to lower case the search terms
This makes it harder to spot the patterns and quite a few times the person who has to do the analysis ends up using the search tools analytics rather than Google Analytics
The downside to this is the search tools analytics rarely has the same level of functionality that Google Analytics has
Hey Julius, great post. Is there any way we can get the values of a search when the search bar isin JS? So when you type you're getting results instantly. No search results urls, no "s" queries...
Thanks!
It looks like you haven't read the guide carefully. Have you tried option #3?
oh, yes, I think this is it. Thanks for the heads up, sometime just read too quick ;-)
Hi Julius,
I am having a minor issue with the search tracking on GA4. For some reason the view_search_results event only seems to appear in Debug when I navigate away from the search results page, as opposed to at the initial load of the search results page. My site uses a standard ?q= query parameter and it does appear in the URL of search results pages as it should.
Do you have any suggestions?
Check the GTM preview mode to make sure when exactly your tag fires. It's difficult to offer a solution without seeing the full situation.
Also, there is a slight delay in the DebugView so there might not be any problems.
The tag is using the built-in 'All Pages' trigger, and the GTM code is in the recommended page locations in HTML.
It definitely doesn't seem top be down to debug view delay, as it doesn't matter if I wait seconds or minutes. But as soon as I navigate away from the search results page, debug view reports the 'view_search_results' event, and then immediately the 'page_view' event for the destination page that I have now arrived on.
I'm not going to lose too much sleep over this issue as it's not a deal-breaker.
Hi Julius!
Thanks for the article!
I have search URL: /search/all?query=search_example and it doesn't return any results in GA4/GA-UA. I've tried your Tracking option #2 but that didn't help either. What can you recommend?
Option #4
Hi,
Im using GA4 for my website which is not an Ecommerce, it's just a blog. Ive created some events with tag manager based on your videos, and Im sending a "value" parameter where Im adding "amounts of money" for click. Events have been converted to conversions in the "Conversions" option in GA4 however when I check the events report under the "Total Revenue" metric, I only see $0 however based on the number of events "Total Revenue" should be more than $0.
Total revenue applies ONLY to purchase tracking in this case.
Thanks Julius for a detailed step-by-step post! This is very helpful.
How can I see queries which were searched from internal search bar in my site inside Google Analytics 4. I'm confused, please help how to do this
Hi. You clearly haven't read this guide till the very end. Everything is explained here.
Hi Julius, thank you for putting together this detailed guide. I'm having a problem once I get to setting up the report in the Analysis hub.
In the step:
In the Variables column, click the Plus icon in the Dimensions section and find search_term. Select it and click Apply.
For some reason, 'search_term' doesn't appear as an option for me.
Any ideas? Thanks.
Have you registered it as a custom dimension? Have you waited for up to 24 hours?
Ah, it's probably to do with waiting the 24 hours. I'll check it again tomorrow. Thanks for your response.
Had the exact same query. Thanks
Hello Julius, first of all let me thank you for this great tutorial, it's been really helpful. I'm struggling with the last step when you're creating the custom report to see the searched terms
In my case I have the search_term variable but the value is always (not set), It's weird as I can check the real time report and see the searched terms there
Also I've created the custom search_term variable and waited for 3 or 4 days but with no luck
Do you have any idea of what I might be doing wrong? Thanks!
I know this is a fairly old comment, but in case anyone else is running into the same problem, do you have a custom dimension set up for search_term? I implemented Tracking Option #3 and was seeing the search terms in Realtime but not in my reports in the Exploration tab. Once I created a custom dimension for search_term, the search terms started showing up in my Exploration tab reports the next day.
Ciao! I need to exclude query parameters in GA4. (e.g., I have a few URLs where firstname= and lastname= are present.). What options do I have as it has been hard to find any resources on this.
Thanks in advance!
Jimi
There is no built-in functionality for that yet. You would need to write custom JavaScript code that strips the unwanted query parameters and insert that variable as the value of "page_location" parameter.
I am pretty sure that this feature is definitely in the roadmap of GA4
Wow! Thank you for the quick reply, amazing! This is the last item I need in place before launching GA4. If I launch without it, I will violate GA's terms of service by including PII in the URL.
Thoughts on if this would work?
In GTM, in the GA4 tag configuration, I can expand fields to set, and specify "page_location" as the field name and add a custom variable called {{remove queries}}
The JS for the custom variable is
function(){
return document.location.hostname + document.location.pathname;
}
This would strip all, I think. Even though I only want to strip specific items.
Stripping ALL query parameters is not a good idea. What about UTMs? What if you have some other useful query parameters?
As for PII in the URL, it would be better to cooperate with devs and ask them to not include PII in the URL. Keep in mind that other tracking tools on your site also get that PII from the URL, hence data leak occurs.
Thanks again for the response. I will continue searching for a solution to strip specific query parameters. I expect dev will take weeks if not more due to other priorities.
Have a great day,
Jimi Grimes
Hi Julius,
Is there any reason in particular why in method #2 you call the event parameter "search_query", whereas in all other examples it is called "search_term"?
That's a mistake. Thanks for pointing out.
Site Search tracking is turned on under data stream > Enhanced Measurement. I thought that was it. I don't see the dimension "search_term" when creating the report, only the total number of searches.
That is why you should read this blog post till the very end because I explain what to do.
Thanks for this guide! I'm wondering if you've figured out how to report search destination pages in GA4? I've been searching everywhere!
Been looking everywhere for this as well and haven't found anything of use.
You can set up a report with a page referrer and set that equal to your site search results page, then add page path and views. Then in Excel you could extract the search terms from the query parameters on your search results page, that alongside the page path metric to get an idea of what the search terms sending traffic to a specific search destination page, but it is convoluted.
I guess similarly you could set your page referrer filter to include your search term query and term and find out what page paths are associated with that... (something like page referrer contains q=search+term) - but again a mess
Hi, thank you for this content. I was wondering if that makes a difference to name the search custom event with the same name as the one suggested by Google "view_search_results" or if it can be named safely like "search"
Currently, it can be anything else too
Hi Julius,
Our site search query uses a hashtag/pound (#) instead of a question mark (?), meaning it's not working with the automatic enhanced measurement. Would that mean the answer for this issue is to add the # into the Search Term Query Parameter field under advanced settings for enhanced measurement? I wasn't able to tell from the other methods you listed.
Also, I've listed some examples of the search URLs below.
Examples:
https://www.website.com/search#q=fun&sort=relevancy
https://www.website.com/search#q=fun&sort=relevancy&f:searchwithin=[Events]
https://www.website.com/search#q=fun&sort=%40itemdate%20ascending
Did this work for you? Ours is formatted the same way.
Is it possible to force lowercase for the search terms when using enhanced measurement? It's problematic that uppercase and lowercase search terms are tracked separately in reports. Or would I have to turn off enhanced measurement and implement via GTM?
You can't lowercase search term tracked automatically by enhanced measurement. But if you have implemented a custom solution, you would need to open the variable that returns the search term, then go to Format value > Change case to Lowercase
Hey Julius,
Thank you so much, your blog and youtube channel are genuinely so great, better than any original Google content & documentation!
I have an important question though - is it possible to show statistics for individual keywords in the search query? All the tutorials online show tables displaying full queries, for example "blue shoes". Is there a way to display a report with individual keywords, and how many times were they used? I wanna see "blue" and "shoes" separately in the table, and if anyone searched for "green shoes" the "shoes" event count would increase.
It seems like an important use case and yet I can't find any info on how to set that up and if it's even possible (I think it might've been with Universal Analytics).
Thank you!
There is no way to achieve this in GA4 interface
Thanks a lot for this great tutorial. My search result has this URL: https://mydomain.com/search?query=dog However, the view_search_results does not show in GA4 debug view - only page_view event - I have enabled the enhanced measurement - any suggestions? Did I setup something wrong? Thanks a lot
Sounds like your website is a single-page application. In that case, you would need to build a custom solution that sends the search event to GA4
Hi Julius!
How would you recommend set up a view with "visits with site search" and "visits without site search" as we can see under "usage" in UA? Is there a way?
I'd also like to know how to see "visits with site search" and "visits without site search" as we can see under "usage" in UA? Is there a way?
I explain that in my GA4 course
Great info was always but unclear why no steps given to implement '1.1. Custom JavaScript Variable' when details is given for all other steps. More details or a link to how to set up a custom variable would help. Thought i was reading the article wrong because normally you give detail
What steps do you need? I provided the code, you create a custom JS variable with that code and use the variable in the tag. That's pretty much it.
Hi! I'm not sure where I fit in terms of the above info. My site is all set up with GA4 - however the automatically created events don't seem correct. Whenever I submit a search, it's showing up as form_ start and form_submit (as are all the other forms). Also view_search_results is nowhere to be found. I'm really struggling on how to fix it.
Hi Julius
Is it correct that hyphens are not allowed in the
Additional Query Parameters?
Hi, awesome post, is there any solution for "friendly mapping" of additional search query? such as ?q=some%20keyword&manufacturer=2234 where 2234 is value of the custom attribute in Magento, and have value of "Old Spice" for example...?
Is it possible to associate orders and revenue to internal search terms, like it does in GA3?
One thing to be aware of is that there is no way to lower case the search terms in GA4 as the filter functionality that GA3 had isn't replicated in GA4
Which means you end up with duplicates terms
When you pass the search term over, always use the lower case format option
Thank you for the post Julius.
Universal Analytics had some KPIs like avg search depth, search exit etc. Are these KPIs deprecated in GA4?
yes
Thanks, this helped me a lot!
Our developers build many TYPO3 websites using the ke_search extension – which uses an array for the search query parameter: tx_kesearch_pi1[sword] ... UA could track it, GA4 doesn't.
I adapted your alternative method #1 and it works fine with this custom JS in GTM:
function() {
var urlParams = new URLSearchParams(window.location.search); //get all url parameters
var searchParam = 'tx_kesearch_pi1[sword]'; //TYPO3 internal search term
if(urlParams.has(searchParam)){
return urlParams.get(searchParam);
} else {
return undefined;
}
}
Maybe https://docs.typo3.org/p/tpwd/ke_search/4.6/en-us/Configuration/SearchWordParameter.html is the way to go?
I've seen this already and for sure it would be the best solution. But you don't always have the possibility to change the website of your clients.
Hey Julius, have followed almost all your guides. They have been very insightful and thanks for always taking a step forward to do the details.
Our internal search term report gets fueled by the search event captured by the data layer.
I have realized that search term report is fueling the report but there are some outliers which are show search term with html code in it. For e.g. why%20use ( the %20 shows as part of search term ). Is there someway to correct this or you can point me in the direction.
Hi Julius!
First of all, thank you for sharing all of your GA4 knowledge. Your videos and articles are amazing!
I am trying to set up a site search report. We use "search_term" for paid and UTM campaigns so the report is also pulling in all that data. What would the source/medium be to help narrow down what is searched on our site? Is there another way to determine what is "site search" versus other methods of search?
Thank you in advance!
Absolutely awesome post!
A question to the community:
We have a Typo3 Website and use ke_search for site search.
While searching, an URL is generated like this:
"example.com/search?tx_kesearch_pi1%5Bsword%5D=example&cHash=9be7fc6cb5133335b1a3b13512186440"
According to an old help article of ke_search it was possible to enter the search query "tx_kesearch_pi1[sword]" in Analytics.
With GA4 unfortunately it is not possible, to enter square brackets.
(The "Save" button is grayed-out).
The use of the URL encoding like "%5B" für "[" also does not help, GA4 is not collecting the site search data.
Does anyone had a similiar problem?
Or is the hash the reason, it doesn't work?
Hi Julius,
My report is showing search termn perfectly. However, the majority shows as (not set). Do you know why this might be happening?
We explored the idea of session timeout but as this is a single event, it should still show right? Especially since a lot of our other search terms do show. Thanks in advance for any advice!
Hi Julius! Thank you for your comprehensive article on how to setup site search. You have been a truly valuable resource for someone now starting to join the world of Analytics.
The way I went about tracking was by creating Variables in GTM for the different search parameters which get stored in the URL, and using those as Event Parameters for the overall Search Event. However, because the Search function automatically updates as soon as the user selects the parameters, it generates duplicate events. Is there a way we can counteract that?
Hello, thank you for the article. is there a away to add a unusually search query parameter like "search.search" for Automatic search tracking (with GA4 Enhanced Measurement)
No
Hi Julius, thanks for the post.
Just a note: the developer checked this article as well and implemented the variable searchTerm instead of search_term. Was wondering about it but then I noticed the screenshot in 3.1 which actually shows searchTerm.
Thanks for the article, Julius! It was very helpful.
In Lightspeed webshops, there is no query parameter in the search; instead, it uses `/search/`. So I applied the first solution for sites without query parameters.
However, I made a small adjustment to the Custom JavaScript Variable in step #1.1. Otherwise, I would get search terms like "test+1+2+3" because the URL would look like `www.domain/search/test+1+2+3/`. I modified the Custom JavaScript to replace the `+` in the URL with a space. It now looks like this:
function() {
var pagePath = window.location.pathname;
var searchParam = '/search/';
if (pagePath.indexOf(searchParam) > -1) {
return decodeURI(pagePath.split(searchParam)[1].split('/')[0]).replace(/\+/g, ' ');
}
}
This way, the parameterValue becomes "test 1 2 3" instead of "test+1+2+3."
I know i am bit late to this post lol. A query, Why is GA4 not showing UTM traffic from email or PPC campaigns, even though UTM parameters are already enabled in the URLs? Any specific settings to look into or etc?
Appreciate your response.