The Query Param Extractor is a Server-Side GTM variable template that extracts the value of a named query parameter from a URL or path string.
- Accepts full URLs (e.g.
https://example.com/path?foo=bar) and path-only strings (e.g./path.php?foo=bar). - Extracts a single named query parameter by key.
- Automatically URL-decodes the extracted value.
- Returns
undefinedcleanly when the input is missing, has no query string, or the parameter is not found. - Handles edge cases such as keys without values and values containing
=characters.
- Add the Query Param Extractor variable to your GTM Server container.
- Set the URL or Path Input field — this can be any variable that resolves to a URL or path string (e.g. a request URL variable).
- Set the Query param to extract field to the exact parameter key you want (e.g.
utm_source,gclid,session_id). - The variable will return the decoded value of that parameter, or
undefinedif it is not present.
| Input | Param | Output |
|---|---|---|
https://example.com?utm_source=google |
utm_source |
google |
/checkout?order_id=ABC%2F123 |
order_id |
ABC/123 |
https://example.com?foo=bar |
missing |
undefined |
/path/no-query |
foo |
undefined |
The Query Param Extractor for GTM Server is developed and maintained by Praba Ponnambalam under the Apache 2.0 license.