Skip to content

substringAfter β€” GTM Variable Template for String

VARIABLES β€Ί STRING
substringAfter EXTENDED String
Direct (.tpl) Apply (.tpl)

Returns the substring after the first occurrence of a delimiter. If the delimiter is not found, it returns an empty string.


String Manipulation

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

Extraction

Pull specific values, segments, or patterns from complex data structures.


Get email domain
INPUT
String To Process: [email protected]
Delimiter: @
OUTPUT
example.com
Delimiter not found
INPUT
String To Process: no-delimiter-here
Delimiter: @
OUTPUT
""

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

substringAfter
String To Process
πŸ’Ύ The string to process.

Supported formats:
  βœ“ String
Delimiter
βœ‚οΈ The delimiter to search for.

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.
String To Process string
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
Delimiter string
substringAfter()


πŸ“œ View Implementation Code
/**
* Returns the substring after the first occurrence of a delimiter.
*
* @param {string} data.src - The string to process.
* @param {string} data.del - The delimiter to search for.
* @param {Function|string} [data.out] - Optional output handler.
*
* Direct-mode specific parameters:
* @param {Function} [data.pre] - Optional pre-processor function to transform src.
*
* @returns {string|undefined} Returns the substring after the delimiter, an empty string if not found, or undefined if input is invalid.
*
* @framework ggLowCodeGTMKit
*/
const substringAfter = function(input, delimiter) {
if (typeof input !== 'string') return undefined;
if (typeof delimiter !== 'string') return '';
const index = input.indexOf(delimiter);
if (index === -1) {
return '';
}
return input.substring(index + delimiter.length);
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// substringAfter - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(substringAfter(value, data.del));
// ===============================================================================
// substringAfter(...) – Apply Mode
// ===============================================================================
/*
return function(value, delimiter) {
delimiter = data.rp1 ? delimiter : data.del;
return out(substringAfter(value, delimiter));
};
*/
πŸ§ͺ View Test Scenarios (4 tests)
βœ… '[example] Get email domain'
βœ… '[example] Delimiter not found'
βœ… Empty string returns empty string
βœ… Non-string returns undefined