Skip to content

fromBase64 — GTM Variable Template for String

VARIABLES › STRING
fromBase64 CORE String

Decodes a Base64-encoded string into its original representation, reversing the Base64 encoding process.


When to Use This

String Manipulation

Transform, clean, and normalize text data for consistent downstream processing.


Examples

Decode simple Base64 string
INPUT
Base64 String: SGVsbG8gV29ybGQ=
OUTPUT
Hello World
Base64 with special characters
INPUT
Base64 String: VGVzdCAxMjMhQCM=
OUTPUT
Test 123!@#

GTM Configuration

This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.

fromBase64
Base64 String
💾 A Base64-encoded string to decode.

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 case). Internal transformations such as case handling will still apply afterward.
Result Handling
Output Function (optional)
⚙️ Optional function to apply to the result before returning it (e.g., str => str + ' €', val => val !== undefined for boolean conversion). Useful for chaining transformations on the output.
Base64 String string
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
fromBase64()


Under the Hood

📜 View Implementation Code
/**
 * Decodes a Base64-encoded string into its original representation.
 * 
 * @param {string} data.src - A Base64-encoded string to decode.
 * @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 string or data from the provided Base64-encoded input.
 *
 * @framework ggLowCodeGTMKit
 */
const fromBase64 = require('fromBase64');

const decodeBase64 = function(base64EncodedString) {
      if (typeof base64EncodedString !== 'string' ) {
        return undefined;
    }
    return fromBase64(base64EncodedString);
};

const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);

// ===============================================================================
// decodeBase64 - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(decodeBase64(value));

// ===============================================================================
// decodeBase64() – Apply Mode
// ===============================================================================
/*
return function(value) {
   return out(decodeBase64(value));
};
*/
🧪 View Test Scenarios (5 tests)
✅ '[example] Decode simple Base64 string'
✅ '[example] Base64 with special characters'
✅ Base64 with padding - handles padding correctly
✅ Base64 encoded number - decodes to string representation
✅ Base64 with URL-safe characters - decodes properly