Skip to content

gtm-templates-praba/query-params-extractor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Query Param Extractor - Server-Side Google Tag Manager Variable

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.

Features

  • 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 undefined cleanly 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.

Getting Started

  1. Add the Query Param Extractor variable to your GTM Server container.
  2. 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).
  3. Set the Query param to extract field to the exact parameter key you want (e.g. utm_source, gclid, session_id).
  4. The variable will return the decoded value of that parameter, or undefined if it is not present.

Example

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

Open Source

The Query Param Extractor for GTM Server is developed and maintained by Praba Ponnambalam under the Apache 2.0 license.

About

A Server-Side GTM variable template that extracts the value of a named query parameter from a URL or path string.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors