Search code examples
looker-studio

How to remove GA Page query parameters using Data Studio calculated fields?


I have Request URIs in my GA Page dimension that look like this:

/this/is/a/webpage.html?parameter=1
/forwarded/from?url=/webpage.html?parameter=1
/this/is/another/webpage.html

I would like to create a calculated field in Data Studio that extracts out the text prior to the first "?" and returns that value.

The ideal output based on the above input would be:

/this/is/a/webpage.html
/forwarded/from
/this/is/another/webpage.html

I tried this:

Calculated Field: Formula:

REGEXP_EXTRACT(Page, '^(.+?)\?')

It returns no records.

This is me playing with the regex https://regex101.com/r/hkqOXA/1 The regex seems valid, Data Studio seems to be failing me here! Please advise on either a workaround or explanation as to why Data Studio doesn't process this as expected!

Thanks!


Solution

  • Try this calculated field:

    REGEXP_REPLACE(Page, '\\?.+', '')
    

    The double back slash is the escape character for the question mark, then the calculated field grabs everything after that and replace it all with an empty string ''.

    Cheers, Ben