Here I explain to you how to track subfolders in Google Analytics with a simple RegEx (regular expression) in a new Data View.
How to set up data views for each of these subfoldersFirst 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-ViewLog 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 SubfoldersYou 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.