decodeUri — GTM Variable Template for URL
decodeUri EXTENDED URL
Decodes a URI by replacing percent-encoded characters.
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
""
GTM Configuration
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
Same category: URL
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