Track Subfolders with Filters in Google Analytics

Here I explain to you how to track subfolders in Google Analytics with a simple RegEx (regular expression) in a new Data View.
To track Subfolders or Subdomains is sometimes quite interesting, depending on the setup of your server-structure or website. When it comes to a little more advanced Data Views in Google Analytics, there sometimes comes the request of a client that they want to see just the results for one or more countries in a new Google Analytics Data View. Or they just want to have one view, for example for one specific category (aka subfolder) of their website.
Tracking Subfolders is sometimes really helpful. A typical case might be that you are country and language-specific subfolders for your website. I myself use for example analysith.com/en/ as a language subfolder for my website. There are many companies out there that do use folders like /de/de and /de/en as subfolders.
An example for a case like that is the a couple of weeks ago newly launched website of Loacker at www.loacker.com. This website uses a few more subfolders.
Because of this setup, the client might want to be interested in tracking the performance either in a language-specific way in one view or broken down to the main parts depending on the main subfolders de, int or it. Personally, I’d prefer having a data view for the language-specific analyzation as well as the analyzation for the main subfolders.
de/de
it/it
int/en
de/en
it/de
int/de
int/it
How to set up data views for each of these subfolders
First of all, you should have a look at your current folder structure. In that special case, it is important to keep in mind that you won’t be able to track the folders only by filtering the first folder de, it and int. But why is that so? The reason is that by just setting a filter for “/de”, the numbers would be messed up because you are having a /de/de, one de/en/, another it/de/ and an int/de/ folder. All traffic arriving in these four folders would be shown in the new Data View. So in the following steps, we are going to work with RegEx to make sure that we are just tracking the traffic for de/de/ and de/en/ but no other language or country-specific folder.Step 1: Create new Data-View
Log in to Google Analytics first of all with the account your Google Analytics property was either set up with or you were granted access to. Open your latest Data View of your Analytics property. As a next step, go to your account settings in the lower left corner as shown in the screenshot below. Next, you should go to “View settings” below the current “View” column and click on “View settings”. A new slide will open up for you. In the upper right corner, you will find a button named “Copy view”, which I marked red in the screenshot in red for you. Press on it and give your new view a new name. As a next step, check whether your brand new view is selected and go to the “Filters” submenu on View Level and follow the next steps.Step 2: Setting the Filters for your Subfolders
You should now create a new filter with the “Add filter” Button in the top left corner of the slider. Give your filter a new name and change (probably you will have to change that) your filter type to custom. As I mentioned earlier, we would need to make sure that we are tracking to right folders. So it’s not going to be enough to just track the /de folder for the part of the website which is for Germany (in German and English). Now you would have to work a little bit with RegEx – which isn’t that complicated at all. RegEx is a Regular Expression so, in theory, a specific string that helps you finding and select specific sequences. According to Wikipedia, a RegEx is defined as follows:A regular expression, regex or regexp (sometimes called a rational expression) is, in theoretical computer science and formal language theory, a sequence of characters that define a search pattern. Usually this pattern is then used by string searching algorithms for “find” or “find and replace” operations on strings, or for input validation.So in that specific case of Loacker, you would need to create a custom include a filter that has a filter field “Request URI” which has the following Filter Pattern:
^/de/de|^/de/en^ means that anything may come in front of the following value. | separates two regular expressions from each other. According to the above Regex, we would like to include both folders, /de/de and the folder /de/en into our Data View. Make sure that your filter is set like within the screenshot below and you are all set. After saving this filter, all following User sessions will be matched with this filter. Past sessions and numbers won’t be affected by the filter so I recommend to document the changes to make sure that you know later for reports when such a significant change in your filter settings took place.