DEV Community


How to get query parameter from URL in Google Data Studio

alfanerd profile image Marcin Masłowski ・1 min read

For example, you want to get query parameters from URLs like this:

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:

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

Now we can create reports based on new fields:

Alt Text


Editor guide