decodeUriComponent β GTM Variable Template for URL
decodeUriComponent EXTENDED URL
Decodes a URI component by replacing percent-encoded characters.
When to Use This
Section titled βWhen to Use ThisβExamples
Section titled βExamplesβDecode spaces
INPUT
URI Component To Decode: hello%20world
OUTPUT
hello world
Decode special characters
INPUT
URI Component To Decode: user%40example.com
OUTPUT
Live Sandbox
Section titled βLive SandboxβThis is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
decodeUriComponent
URI Component To Decode
πΎ The URI component to decode, which may contain percent-encoded characters.
Supported formats:
β String
Supported formats:
β String
Input Setup
Input Function (optional)
βοΈ Optional pre-processing function applied to the input before internal logic (e.g., convert object to string, normalize format). Internal transformations such as string handling will still apply afterward.
Result Handling
Output Function (optional)
βοΈ Optional function to apply to the result before returning it (e.g., str => str.toLowerCase(), val => val + ' decoded' for string modifications). Useful for chaining transformations on the output.
URI Component To Decode string
π‘ Type any text to see the result update live
π― Using special value β click input to type instead
Test with:
Falsy
Truthy
π Result Handling β Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
decodeUriComponentFunction()
Related Variables
Section titled βRelated VariablesβSame category: URL
Under the Hood
Section titled βUnder the Hoodβπ View Implementation Code
/** * Decodes a URI component by reversing percent-encoding for special characters. * * @param {string} data.src - The URI component to decode (e.g., a query parameter or path segment). * @param {Function|string} [data.out] - Optional output handler: function to transform result or string with format. * * Direct-mode specific parameters: * @param {Function} [data.pre] - Optional pre-processor function to transform src before decoding. * * @returns {string} The decoded URI component with percent-encoded characters converted back to their original form. * * @framework ggLowCodeGTMKit */const decodeUriComponent = require('decodeUriComponent');
const decodeUriComponentFunction = function(uriComponent) { if (uriComponent == null) { return ''; } const stringValue = typeof uriComponent === 'string' ? uriComponent : uriComponent.toString(); return decodeUriComponent(stringValue);};const safeFunction = fn => typeof fn === 'function' ? fn : x => x;const out = safeFunction(data.out);// ===============================================================================// decodeUriComponent - Direct mode// ===============================================================================const applyCast = (castFn, value) => safeFunction(castFn)(value);const value = applyCast(data.pre, data.src);return out(decodeUriComponentFunction(value));// ===============================================================================// decodeUriComponent() β Apply Mode// ===============================================================================/*return function(value) { return out(decodeUriComponentFunction(value));};*/π§ͺ View Test Scenarios (6 tests)
β
'[example] Decode spaces'β
'[example] Decode special characters'β
Encoded query parameters - decodes ampersand and equalsβ
String without encoding - returns unchangedβ
Empty string - returns empty stringβ
Non string input - return it stringified