decodeUri β GTM Variable Template for URL
decodeUri EXTENDED URL
Decodes a URI by replacing percent-encoded characters.
When to Use This
Section titled βWhen to Use ThisβExamples
Section titled βExamplesβDecode %20 to spaces
INPUT
URI To Decode: https://example.com/path%20with%20spaces
OUTPUT
https://example.com/path with spaces
Null returns empty string
INPUT
URI To Decode: null
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.
decodeUri
URI To Decode
πΎ The URI 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 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.
decodeUriFunction()
Related Variables
Section titled βRelated VariablesβSame category: URL
Under the Hood
Section titled βUnder the Hoodβπ View Implementation Code
/*** Decodes an entire URI (Uniform Resource Identifier), reversing percent-encoding for special URI characters.** @param {string} data.src - The URI to decode, which may contain percent-encoded characters.* @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.** @framework ggLowCodeGTMKit*/const decodeUri = require('decodeUri');
const decodeUriFunction = function(uri) { if (uri == null) { return ''; } const stringValue = typeof uri === 'string' ? uri : uri.toString(); return decodeUri(stringValue);};const safeFunction = fn => typeof fn === 'function' ? fn : x => x;const out = safeFunction(data.out);// ===============================================================================// decodeUriFunction - Direct mode// ===============================================================================const applyCast = (castFn, value) => safeFunction(castFn)(value);const value = applyCast(data.pre, data.src);return out(decodeUriFunction(value));// ===============================================================================// decodeUriFunction() β Apply Mode// ===============================================================================/*return function(value) { return out(decodeUriFunction(value));};*/π§ͺ View Test Scenarios (5 tests)
β
'[example] Decode %20 to spaces'β
URI with encoded non-reserved characters - decodes themβ
URI without encoding - returns unchangedβ
'[example] Null returns empty string'β
URI with both reserved and non-reserved encoded characters - shows difference