How to get query parameter from URL in Google Data Studio
Marcin Masłowski
Posted on February 2, 2020
For example, you want to get query parameters from URLs like this:
www.mystore.com/search?q=shoes&color=red
To simplify the process I use Google Sheets as a data source. But you can use raw data from Google Analytics as well:
When we have this data in Google Data Studio our goal is to have query parameter as separate columns in our report like this:
To do this we have to create, a new field, and use REGEXP to extract the data from URLs:
In code below "q" is the query parameter you want to extract for example "color":
REGEXP_EXTRACT(URL, 'q=([^&]+)')
~~~~
If you use Google Analytics as a data source, change the URL with PAGE dimension:
REGEXP_EXTRACT(Page, 'q=([^&]+)')
~~~~
Now we can create reports based on new fields:
💖 💪 🙅 🚩
Marcin Masłowski
Posted on February 2, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.