Google Data Studio – Parameter value from URL

The Google Data Studio calculated field below extracts the value of a specific parameter and returns it as a text / string.

  • Input
    • Field corresponding to the URL / Page address with parameters (test / string)
      • Example 1 – Full URL: https://www.site.com/folder/page.html?param1=value1&wishedparam2=wishedvalue&param3=value3
      • Example 2 – Path & parameters: /folder/page.html?param1=value1&wishedparam2=wishedvalue&param3=value3
    • URL parameter key / name (string) of the wished value
      • Example: wishedparam2
  • Output
    • Value of the specific URL parameter
    • Type: text / string
  • Calculated field formula
    • REGEXP_EXTRACT(<My url field>,”^(?:.*)(?:\\?|&)<My parameter key>=([^&]+)(?:.*)$”)
  • Example
    • Get the parameter value “site_search_kw” from Google Analytics page dimension:
      REGEXP_EXTRACT(Page,”^(?:.*)(?:\\?|&)site_search_kw=([^&]+)(?:.*)$”)