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 drupal.org. 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:
- Choose “Custom” and “Advanced” as the filter type.
- 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.
- In Field B, leave it blank. We don’t need a second field for anything here.
- For the Output To field, select Search Term, and enter
$A1in the input. That says “grab the first set of parenthese from Field A”, which contains our search term.
- Save the filter.
And that’s it! Like all admin settings, it will only take effect on your data going forward.
About Jonathan Weber
Jonathan Weber is the Data Evangelist at LunaMetrics. He spreads the principles of analytics through our training seminars all over the East coast. The next seminar he'll be leading will be a Google Analytics training in Boston. Before he caught the analytics bug, he worked in information architecture. He holds a Master’s degree from the University of Pittsburgh School of Information Sciences. Jonathan’s breadth of knowledge – from statistics to analysis to library science – is somewhat overwhelming.