Skip to content

stripAccents — GTM Variable Template for String

VARIABLES › STRING
stripAccents EXTENDED String
Direct (.tpl) Apply (.tpl)

Replaces accented characters with their closest ASCII equivalents. Preserves the original case of the string. This is the GTM sandbox equivalent of .normalize('NFD').replace(/[\u0300-\u036f]/g, ''), which is not available in the sandboxed JavaScript environment.


String Manipulation

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

Formatting

Normalize casing, spacing, encoding, and presentation of data values.

Type Conversion

Safely convert between data types — strings, numbers, booleans, arrays, objects.


French accents
INPUT
Text To Strip: Café résumé naïve
OUTPUT
Cafe resume naive
German umlauts and eszett
INPUT
Text To Strip: Über große Straße
OUTPUT
Ueber grosse Strasse
Non-string returns undefined
INPUT
Text To Strip: 12345
OUTPUT
undefined

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

stripAccents
Text To Strip
💾 The string from which to remove accented characters.

Supported formats:
  ✓ String
Input Setup
Input Function (optional)
⚙️ Optional pre-processing function applied to the input before stripping accents.
Result Handling
Output Function (optional)
⚙️ Optional function to apply to the result before returning it (e.g., toLowerCase(), slugify). Useful for chaining transformations on the output.
Text To Strip string
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
stripAccents()


📜 View Implementation Code
/**
* Replaces accented characters with their closest ASCII equivalents.
*
* GTM sandbox alternative to .normalize('NFD').replace(/[\u0300-\u036f]/g, ''),
* which is not available in the sandboxed JavaScript environment.
*
* Handles both uppercase and lowercase accented characters, preserving
* the original case of the surrounding text. Multi-character replacements
* (ß→ss, æ→ae, œ→oe, þ→th, Æ→AE, Œ→OE, Þ→Th) follow standard
* transliteration conventions.
*
* @param {string} data.src - The string to strip accents from.
* @param {Function|string} [data.out] - Optional output handler.
*
* Direct-mode specific parameters:
* @param {Function} [data.pre] - Optional pre-processor function.
*
* @returns {string|undefined} The string with accents replaced, or undefined if input is not a string.
*
* @framework ggLowCodeGTMKit
*/
const stripAccents = function(input) {
if (typeof input !== 'string') { return undefined; }
var map = {
'à':'a','á':'a','â':'a','ã':'a','ä':'ae','å':'a','æ':'ae',
'ç':'c',
'è':'e','é':'e','ê':'e','ë':'e',
'ì':'i','í':'i','î':'i','ï':'i',
'ð':'d','ñ':'n',
'ò':'o','ó':'o','ô':'o','õ':'o','ö':'oe','ø':'o','œ':'oe',
'ù':'u','ú':'u','û':'u','ü':'ue',
'ý':'y','ÿ':'y','þ':'th','ß':'ss',
'ł':'l','đ':'d',
'ž':'z','š':'s','č':'c','ř':'r','ě':'e','ů':'u',
'ń':'n','ň':'n','ś':'s','ź':'z','ż':'z',
'ą':'a','ę':'e','ć':'c',
'ő':'o','ű':'u',
'ğ':'g','ı':'i','ş':'s',
'ť':'t','ď':'d','ľ':'l','ĺ':'l','ŕ':'r',
'À':'A','Á':'A','Â':'A','Ã':'A','Ä':'Ae','Å':'A','Æ':'AE',
'Ç':'C',
'È':'E','É':'E','Ê':'E','Ë':'E',
'Ì':'I','Í':'I','Î':'I','Ï':'I',
'Ð':'D','Ñ':'N',
'Ò':'O','Ó':'O','Ô':'O','Õ':'O','Ö':'Oe','Ø':'O','Œ':'OE',
'Ù':'U','Ú':'U','Û':'U','Ü':'Ue',
'Ý':'Y','Ÿ':'Y','Þ':'Th',
'Ł':'L','Đ':'D',
'Ž':'Z','Š':'S','Č':'C','Ř':'R','Ě':'E','Ů':'U',
'Ń':'N','Ň':'N','Ś':'S','Ź':'Z','Ż':'Z',
'Ą':'A','Ę':'E','Ć':'C',
'Ő':'O','Ű':'U',
'Ğ':'G','İ':'I','Ş':'S',
'Ť':'T','Ď':'D','Ľ':'L','Ĺ':'L','Ŕ':'R'
};
var result = [];
for (var i = 0; i < input.length; i++) {
var c = input.charAt(i);
var r = map[c];
result.push(r !== undefined ? r : c);
}
return result.join('');
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// stripAccents - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(stripAccents(value));
// ===============================================================================
// stripAccents() – Apply Mode
// ===============================================================================
/*
return function(value) {
return out(stripAccents(value));
};
*/
🧪 View Test Scenarios (11 tests)
✅ '[example] French accents'
✅ '[example] German umlauts and eszett'
✅ Spanish with ñ
✅ Scandinavian characters
✅ Czech and Polish characters
✅ No accents - unchanged
✅ Ligatures - æ and œ
✅ Turkish characters
✅ Mixed case preserves case
✅ '[example] Non-string returns undefined'
✅ Empty string returns empty