Google Analytics Site Search with SEO-Friendly URLs


Google Analytics has great site search tracking features, but they rely on the URLs of your search results pages having a query parameter (the part of the URL after a question mark, with something like “?searchterm=testing” when you search for “testing”). There are ways around this to track site search without a query parameter (that’s an oldie but still a goodie from 2010), but all those workarounds involved adding or altering the code on your site in some way. But now there’s actually a new way to go about this for some URL structures that involves no code at all.

Site Search URLs without Query Parameters

Lots of sites eschew query parameters in favor of more SEO-friendly (and people-friendly) URLs, including on search results pages. Drupal sites are a common example, where instead of “?searchterm=testing” they use URLs like “/search/site/testing”. Here’s an example from If your site has URLs like this, where the search term (“testing”, in this case), appear in the URL but not in a query parameter, you’re in luck.

Google Analytics Site Search Filter

You already know you can use filters to do things like exclude an IP address from your Google Analytics data. But you can also use them to manipulate data, for example to pull data from one field to another. And recently, Google Analytics updated the list of filter fields to include the site search term, so we can make use of that to fill in the search term field. No code required!

To create this filter, you need to be an administrator. Create a new filter for your profile, and set it up this way:

Site Search extraction filter

  1. Choose “Custom” and “Advanced” as the filter type.
  2. In Field A, choose Request URI (that’s the page, the field we want to grab). Use a regular expression to match the part of the URL you want in parentheses. In my example URL “/search/site/testing” where “testing” is the search term, that would be /search/site/(.*). Your URLs may be different or more complicated, so adjust your regular expression accordingly. Read more about regular expressions in our ebook on regular expressions for Google Analytics, and more about advanced filters.
  3. In Field B, leave it blank. We don’t need a second field for anything here.
  4. For the Output To field, select Search Term, and enter $A1 in the input. That says “grab the first set of parenthese from Field A”, which contains our search term.
  5. Save the filter.

And that’s it! Like all admin settings, it will only take effect on your data going forward.

Jonathan Weber is our Data Evangelist, focusing on bringing the strategic value of data analysis to our customers. He spreads the principles of analytics through our training seminars and even wrote a book on Google Analytics & Tag Manager. Before he caught the analytics bug, he worked in information architecture. Away from the computer, you can find him as a flower farmer and plant geek.

  • Hi,

    thanks for the suggestion. One quick question, also regarding more modern site search implementations: What is in your opinion the best way to track search preview (i.e. type ahead) layers? Often the user (e.g. in e-commerce shops) jumps directly to a product page and never sees a site search page – where would you execute the Google Analytics site search tracking and how?

  • Bjoern — good question, to which there is no 100% best answer. I’d probably record a virtual pageview for the preview with a search query parameter (so I’d see that in the search terms report like any other search), and possibly an event to capture the click on the preview (to differentiate from navigation from an actual search results page).

  • Jules

    Hi Jonathan, this is a great post. I’ve been wanting to figured out enabling the search feature but sadly client’s site runs on drupal! It’s a bit difficult going to the developer all the time with edits.

    I got a silly question what query parameter do we write under the “track site search” option?

  • Google Analytics Site Search tracking features is really nice, it helps me very much. SEO-Friendly URLs is positive for SEO ranking.

  • Pedders

    Hi Jonathan

    Great post!

    Could be I’m doing something wrong, but set up a separate profile in GA for my client and added the parameter /search/(.*)

    Then went to client’s site and did 4-5 searches, but nothing showing up still 72 hrs later??

    Have I missed something?

    E.g. Do I need to tick the track in-site search option and then just leave blank?


  • Jens

    You may want to add a $ symbol to the end of your Regex for request URI. In our case, when people navigated to the second page of the search results, that also generated keywords.

    The uri for that was /search/site/searchterm?page=1

    So to make sure you only get initial searches and not navigational URL’s in search results, you should add the $ symbol to indicate you need the search term to be the last thing in the URL. If you have the same URL structure as we do for the search results page of course.

  • Jens

    Okay, to be fair, my reply above makes no sense. Why I thought that would work, I don’t know.

    But the problem remains, there are still irrelevant ‘search terms’ being generated by using this solution.

    Jonathan, do you think there is another solution to prevent this? Or should we go ahead and use the older method described in this post:

    Thanks for your reply!

  • Jens — not sure about your particular situation, but one thing you can check is the regular expression you are using and making sure it is only matching search results pages. Take your regular expression and try it in the All Pages report and make sure it’s only matching the search results pages (using the “advanced” filter link at the top of the table of data). You may need to make your regular expression more or less strict to make sure you get just the pages you really want.

  • Oh, and looking more closely at your example above, what you might want is something like this:


    Which will just grab the part between “/search/site/” and a question mark.

  • Hi Jonathan,

    I was just speaking to a client on the importance of tracking site searches using GA which can’t be overemphasized and I’m in the process of setting up site search tracking for the client.
    I have a question though – Like Jules asked above, what Query Parameter (such as q, s, search etc) do you recommend we put down in “Site Search Setting” box?


  • Hola! I’ve been reading your website for a long time now and finally got
    the courage to go ahead and give you a shout out from New Caney
    Texas! Just wanted to say keep up the good job!

  • hi

    it looks like an important question has still not been answered
    so I dare to be the third person asking 🙂

    what parameter should we enter in View Settings under Query Parameter?

    and another more advanced question:

    what about Site search categories? Is there an even more advanced solution in case of more complex, advanced search feature?

    thanx in adv

  • hi

    it’s me again
    it looks like no one has answered my question however meanwhile I adjusted my Analytics account and it works pretty well with the default Site search settings to ON
    Basically since we use an advanced filter, Analytics takes in account this settings for the Site search stats

    Still, thre would be one more concern that’s of multiple term searches (more than 2 words used)
    At the moment in the report I get “term1+term2+term3” since this way is generated the URL
    now I would need a regular expretion or another filter option which extracts the ‘+’ signs and replaces with a space
    I’ll work on this issue however if any of you have a prompt solution, I would highly appreciate

  • Hi all — you don’t have to put anything in the site search parameter setting. You’re not using a parameter; the filter takes care of filling in the field.

  • And Phil — yes, if you have characters like + that you want to transform into spaces, you’d have to do that with some additional filters to replace them. If your URL uses encoded spaces (%20), they should be correctly decoded by GA, but if it uses + or something else, you’d have to use a filter.

  • Bump!
    Was contemplating ditching the rewrite. Then contemplating ditching my GA plugin for including GA myself and handing this the “old way”.
    Glad I found this thanks =)

  • Les

    Hey Jonathan: This is great stuff. I have been struggling with gathering internal site search stats on close to 10 Drupal sites. The best I could do in the past was create a custom report that capture the URIs in question (Sloppy IMHO).

    So – to be clear:

    1) Create the advanced custom filter in whatever VIew you want it applied to (Or perhaps setup a test view first?)
    2) Do not turn on Site Search in that view. I tried turning on Site Search, but GA demands something be inputted in the query parameter.
    3) Internal Site Search data will flow into Reporting > Behavior > Site Search

    Question: What about multilingual Drupals sites where you have /en/search/node/searchterm (English) & /fr/search/node/searchterm (French)? Would I do two filters? Or combine into one using RegEx: en|fr/search/node/(.*)?

    I am so excited!

    PS Please setup comment subscription on your blog. 🙂

  • Some medications such as antidepressants and blood pressure medicines cause dry mouth.
    A root canal may also be done if a nerve has been damaged due to the decay.
    Practicing a healthy oral hygiene routine and arranging for your
    tooth extraction to occur during the week of your placebo pills can help to prevent complications from occurring.

  • Manatax

    Hey jonathan,
    I tried what you posted and deleted also the query parameter but I get this.
    Query parameter:
    This value must be non-empty.

  • Thanks for the information, testing at this very moment. I do have the search site activated with a randon parameter but I read from the comments you gotta leave the site search deactivated!? sounds strange, can anyone confirm?

  • Hi, I have a problem with this and my URL is /search/searchresult/ and after I do a search there is same URL. Not like /search/searchresult/testing What is the solution of this?

    • Adam Bowker

      If you are using a tag management system, you could probably use javascript to grab the value of the search term and fire a (virtual) pageview to the same base url with ?q={{search term}} — and then set up q to be a search parameter in GA.

  • Huong Nguyen

    Thanks for sharing solutions, it is really understandable
    But i have a case i still concern that, if URL search no search term shown. How we can control that
    Something like :/event/search
    Thanks for your help

Contact Us.

Follow Us



We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203


4115 N. Ravenswood
Suite 101
Chicago, IL 60613


2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187