Reporting on Top Level Directories and Subfolders in Data Studio

custom field with regex in data studio

A simple custom field in Google Data Studio will allow you to create separate dimensions for each subfolder which works for Google Analytics, Google Search Console and really any connector where the dimension is a URL.

To do this follow these steps:

1. Edit your data connection in data studio
2. Click on add field 
3. Paste in the formula – REGEXP_EXTRACT(URL, ‘^https://[^/]+/([^/]+)’)
4. Remember to give the field a unique name like “Top-level directory”
Bonus – If you want 2nd level directories paste in – REGEXP_EXTRACT(URL, ‘^https://[^/]+/[^/]+/([^/]+)’)

This is great for showing what sections of your site are winning and great for international SEO for spotting misaligned traffic if you add the Country dimension on top of.

Here’s some other great resources on segmentation in Google Data Studio: 

If you have any other use cases of segmentation or found this useful feel free to comment!

Author: Daniel Liddle

Global SEO expert specialising in strategy, content, data, tech and automation.