Edit
Contact us
Salocin Group Leaders in data and AI-enabled connected customer experiences
Edit Engineers of connected customer experiences
Join the Dots Independent, data-led media thinking for sustainable growth
Wood for Trees Optimisers of future fundraising performance
  • Home
  • Our services
    • Cloud solutions
    • Data science
    • Modern Data Platform
    • Privacy and AI compliance
  • Our partners
    • Microsoft
    • Apteco
    • Salesforce
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Salocin Group
    • Careers
  • Contact Salocin Group
  • Home
  • Who we are
    • B Corp
    • Careers
  • Our work
  • What we do
    • Intelligent data
    • Marketing technology
    • Transformational CRM
    • Our technology partners
    • Privacy review
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • Contact Edit
  • Home
  • Broadcast media
  • Digital media
  • Print
    • Direct mail
  • Data
    • Our work with Herdify
    • EPiC
  • Media agency
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Join the Dots
    • Careers
  • Contact Join the Dots
  • Home
  • Services
    • Actionable insight
    • Data discovery
    • Data engineering
    • Data hygiene
    • Privacy review
  • Products
    • InsightHub
    • Apteco
    • Microsoft
    • Data management
    • Consent and preference management
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Wood for Trees
    • Operating principles
    • Careers
  • Contact Wood for Trees
Blog

How to extract site search terms from subfolders in Google Analytics

By Edit | 20 Jan 2016

We published this a long time ago…

Some of the content in this post might be out of date, and some images and links may no longer work.

Discover who we are and how we may be able to help you today:

Learn more

Google Analytics has a lot of really nice features. This post will combine two of them: filters and internal site search. I am a big fan of monitoring internal site search queries. Google gives good guidance for query parameter-based search and for post-based searches, but there is little to no guidance on how to extract site search data for site searches that generate brand new subfolders (or subdirectories, if you’d rather).

You will need:

  1. Admin access to Google Analytics
  2. A site whose internal site search generates subfolders
  3. A testing profile
  4. Use of advanced filters (example below)
  5. An understanding of RegEx (example below)

‘A site whose internal site search generates subfolders’: What does that even mean?

I got the idea for this blog post because one of our clients has an internal site search that generates URLs that look like these, where the search query (“foobar”) is within its own subfolder:

https://www.example.com/search-results/foobar/1/

This kind of site search generation is not supported by Google Analytics by default, so this post is a tutorial for how to generate a report that looks like this:

Write RegEx to replicate your internal site search URL structure

Using the example above, their URL structure for internal site searches looks like this:

/search-results/[search_term]/[page_number]/

Our end goal is to extract the search term from the second subfolder. To do this, we need to write some RegEx (I have a few good references in another post) that separates the non-search components from the search terms. This can be done by using round brackets () to group parts of the URL together.

So the example above translates to:
(^/search-results/)(.*)(/[0-9]*/$)

Which says:

  • The first section begins with “/search-results/” (denoted by ^)
  • The second section can be any string of characters (denoted by .*)
  • The final section is a number (denoted by [0-9]*/$)

This can modified depending on how your internal site search folder structure looks.

Use an advanced filter to extract the search term

In Google Analytics, you need to create a new advanced filter to extract the search term from the URL:

PRO TIP: Always test a new filter on a testing profile before adding it to your main reporting profile.

An advanced filter in Google Analytics works using one or two fields to extract data from (input fields) and combine it into a final field (output field).

Google Analytics reads input fields as RegEx groups, which is why we wrote the RegEx as we did above. Google will then translate your groups in “A1, A2, A3…” and “B1, B2, B3…”. In this example, “/search-results/” becomes “A1”, the search term becomes “A2” and the page depth becomes “A3”. We do not have any “B” terms as we are only interested in extracting data from one dimension.

You then specify what you want to extract, and in this case it is that second group within the RegEx. We want to extract “A2” and implement it as a search term.

This results in a filter that looks like this:

This says:

    1. Look for URLs (request URI) structured as defined in the RegEx [Field A->Extract A]
    2. Extract the second part of that URL [$A2]
    3. Place this as your search term [Output to ->Constructor]

Save your filter.

Now if you go to your Behaviour>Site Search>Search Terms report, you should have a list of terms that people are searching for on your site.

We published this a long time ago…

Some of the content in this post might be out of date, and some images and links may no longer work.

Discover who we are and how we may be able to help you today:

Learn more

Share this

  • Email
  • WhatsApp
  • LinkedIn
  • Facebook
  • X (Twitter)

More insights

AI isn’t going to take your job (unless you really want it to) 
Blog

AI isn’t going to take your job (unless you really want it to) 

By Edit | 18 Jun 2024
Customer relationship marketing: How generative AI is revolutionising engagement  
Blog

Customer relationship marketing: How generative AI is revolutionising engagement  

By Edit | 4 Apr 2024
Personalisation as a process
Blog

Personalisation as a process

By Edit | 8 Mar 2024
  • Privacy policy
  • Cookie policy
  • Ts&Cs
  • Report a concern

© 2025 Edit, part of Salocin Group Ltd. All rights reserved. Company no.: 0362​4881. VAT no.: 4208​34911.

Salocin Group Certified B Corporation | Cyber Essentials Certified | British Assessment Bureau, ISO 27001 Information Security Management
Salocin Group
Your cookie preferences

We use cookies to ensure this website functions properly, to analyse website traffic and for marketing purposes.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}