How to get query parameter from URL in Google Data Studio

alfanerd

Marcin Masłowski

Posted on February 2, 2020

How to get query parameter from URL in Google Data Studio

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:

Alt Text

When we have this data in Google Data Studio our goal is to have query parameter as separate columns in our report like this:

Alt Text

To do this we have to create, a new field, and use REGEXP to extract the data from URLs:

Alt Text

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:
Enter fullscreen mode Exit fullscreen mode

REGEXP_EXTRACT(Page, 'q=([^&]+)')
~~~~

Now we can create reports based on new fields:

Alt Text

💖 💪 🙅 🚩
alfanerd
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.

Related