How To Track Internal Site Search Terms in Google Analytics [All URL Formats]

Capturing Internal Site Search Terms data in Google Analytics is critical to understand the user’s search intent. It will also help you analyze your website UI/UX much better.


The Site Search Reports are available at Behavior > Site Search



As per Avinash Kaushik, here are some of the questions answered through the site search reports.

  • What is the Frequency of Site Search Usage?
  • What are the Pages from where the Users Initiate Searches?
  • Are Users satisfied with the Search Results?
  • How Different Groups of Users Search Your Site?
  • What is the business outcome if users search on your site?




But Why My Google Analytics Site Search Doesn’t Work?

When the user searches for any keyword in your internal website site search, the URL pattern is generated.

This URL Pattern varies for different types of website, & it depends on your CMS.

Sometimes even after the successful search, the Search URL may or may not contain the Query Parameter or even worse, the Search Term itself!!

But Remember, You can always have a hack around it.

Google Analytics has the option to track the site search, ONLY IF you have the Search Term in Query String Parameter of URL.
OR‘, etc




What If..

Query Parameter is present in the URL, but still, Site Search Doesn’t Work

You have to ensure that the google analytics code fires when the URL contains the search parameter. To make sure that the analytics will capture the search term, do the following check.


Step – 1: Check if the Google Analytics Hit contains the URL parameters.

Open your Browser Debugger by pressing Ctrl+Shift+C (windows) or  Command + Option + I (MAC)

Do a search > Go To Networks Tab > Filter GA requests by ‘collect?‘ & check if the pageview hit contains the search term in URL Query string parameters.




If it doesn’t…

then ask your developer to retain the query parameters, you have the option to strip it out in analytics too.

Avoid Redirects if possible.


Step – 2: Choose Correct View & Turn on Site Search Feature.

Make sure to choose the correct view & turn on the site search feature.

After turning it on, add the search query parameter, in the last case it would be ‘s’

So for

  • ?d=desktop&search-term=facebook+custom+events‘ it would be ‘search-term’
  • ?q=facebook+custom+events‘ it would be ‘q’
  • & so on..

It doesn’t matter what comes before the ‘?’ , if your search term is in the query string.

& then you’re ready to go.



What If Query Parameter is not present in the URL

Kind of like ‘/search/[KEYWORD]’…

Then, it is obvious that google analytics site search won’t work just by enabling it in View Settings.

There are 2 ways to get around with it

  1. Use Advanced View Filter.
  2. Modify The URL to add the Query Parameter.


1.) Using Advanced View Filter

Go To View > Filters > Select Custom > Select Advanced Checkbox.

In the Field A — > Extract A

  • Select Request URI
  • Enter Search URL Format

Eg: If your user searches for ‘facebook events’ & your URL is of type

  • “”   then enter /search/(.*)
  • “”  then enter /search-keyword/(.*)
  • “”  then enter /find/(.*)/search

In the Output To –> Constructor:

  • Select Search Term
  • Enter ‘$A1’


Google Analytics Site Search Filter


Note: Select Request URI in Field A  –> Extract A (I forgot this in the gif :/)

Click Save & You’re Done.


2.) Modifying the URL to contain the Query Parameter.

So in simple words, if you have the URL like ‘{Keyword}

You can simply modify it & send it to analytics as ‘{Keyword}’.

Now you can enter ‘q’ parameter in the GA site search & start tracking.

Check out the method described below.


What if…

URL has 1+ search terms with no Query Parameter

So, if you have a site where search URL has one or more parameters in the format

  • Location+Service
  • Category+Sub-Category
  • & so on..

Lets, take an example



If you are using GTM, you can create a Custom Javascript variable named ‘Modified URL’ & use it to fire Analytics Pageview.

In the below code, enter the URL format as ‘{city}-{service}’  the output would be



Site Search URL Tracking in Google Analytics

Then you can simply use the site search option & enter ‘city’ & ‘service’.

Follow the below steps if you are using GTM.

Step – 1:

In GTM, Create a Custom JS Variable (Modified Search URL)  & paste the following code.

Custom Javascript Code: (Modify the URL variable to match your search format)


You can use the above script for variety of URL formats

  1. /search/newyork/gyms  —-> Format: /search/{city}/{service}
  2. /search/newyork/gyms/premium —> Format: /search/{city}/{service}/{membership}
  3. /search/newyork-gyms/premium —>Format: /search/{city}-{gyms}/{membership}
  4. etc


Note: You can use any named variable. 


Step – 2:

Create/Modify Your Analytics. In the Fields To set options, enter the page & the value as the Custom JS variable.


Site_Search_URL_Modification - Google Analytics


Step – 3:

You can use All Pages or Only search pages trigger.

Note: The Modified URL will only be sent when the actual search URL matches the Search URL format you inserted. On the rest of the pages, it will send the normal URL.

Make sure to debug if your trigger is all pages. (Test Image)




What if

URL has search terms in URL as well as in Query Parameter

So, If your site uses IP tracking & When the user searches for “Best gyms in new york”  & URL is like


In this case, you’ll have to use

  • Advanced View Filter. 
  • Site Search Parameter Option.


  • Modify the URL to Query parameter & Use
  • Site Search Parameter Option.


URL has NO search terms in URL as well as in Query Parameter

If you have POST based search on your website,  you can take help of your developer to pass the search term as the query parameter.

For Eg:

Search URL : to

Modified URL:

Then you can implement our normal site search tracking method.



Do You Want To Strip Query Parameters in the Analytics Reports?

What format do you prefer??


Page Pageviews
/search/ 12


Page Pageviews
/search/facebook+events 6
/search/google+analytics 4
/search/how+to+do+analytics+audit 2


If you prefer the first one & you are using Query Parameters, you can simply check the box in site search settings.

If not…

Then create view filter > Search & Replace & paste the following as per your URL format.



Important Points:

  • Make sure to check the URL in the console, if it has the Query parameters.
  • If you are using one or more search terms in the URL, make sure to input the same format in the GTM url variable.
  • Lastly, comment if you have any doubts or I have missed any URL format. 🙂


More Awesome Articles…

Super Guide To Enhanced Ecommerce Tracking via Google Tag Manager [2018]

Google Analytics Audit Checklist – Complete Guide

Automated Cost Data Import – Facebook To Google Analytics

Advanced Guide To Cohort Analysis in Google Analytics

Ritwik is Web Analyst & Growth Hacking Consultant. He loves to write technical & easy to understand blogs for Marketers & Entrepreneurs. Focused on Google Analytics, Tag Management, GScripts & more. Google Certified Professional. A Firm Believer in Teaching -> Learning -> Growing. :)

One comment

  1. Hi Ritwik,

    thanks for his post. I had already set it up and was waiting for results. After a couple i noticed the search pages does show data, i got a searchfield on almost all pages. When i click one page i can see the search terms being used on that page. However when i use the Search Term link on the left, sometimes it does show data and other times it doesnt. When it does show the data, it shows 19 hits and shows 1-10 rows, when i than want to view the other rows suddenly all data is gone and its back to 0???

    Say i click the index page / than after that sometimes it does show the queries and othertimes it doesnt seem to work. It looks like its very buggy or something. Im no guru at this and hardly understand all of this. I just tried this today and see if this could help us. The site isnt really published or given any social appearance, no traffic at the moement.

Leave a Reply

Your email address will not be published. Required fields are marked *