Advantages and possibilities of Custom JavaScript Variables 

Custom JavaScript Variables in Google Tag Manager

Google Tag Manager Tutorial
By Ralph Grundmann · Last updated on 24.02.2026

Custom variables (especially Custom JavaScript Variables) of Google Tag Manager are a powerful tool to eliminate tracking issues. Custom variables require a single anonymous function that returns a value. Custom JavaScript Variables often use other Tag Manager variables as input and return a modified version of that as output.

In simple terms, you can use individual JavaScript variables to utilize other variables, process or manipulate them with JavaScript, and convert and output them into a new variable.

A small list of additional variables for use in GTM

Useful custom JavaScript variables

1

String in uppercase

1
2
3
4
5

function() {

var StringLowerCase = “{{string in lowercase}}”;
var StringUpperCase = StringLowerCase.toUpperCase();;
return StringUpperCase;
}

2

String in lowercase

1
2
3
4
5

function() {

var StringUpperCase = “{{String in Uppercase}}”;
var StringLowerCase = StringUpperCase.toLowerCase();
return StringLowerCase;
}

3

Remove special characters from string

1
2
3
4
5

function() {

var StringInclSpecialChars = “{{string with special characters}}”;
var StringExclSpecialChars = StringInclSpecialChars.replace(/[A-Za-z0-9_]/g, ”)
return StringExclSpecialChars;
}

4

Convert German umlauts to character sequence

1
2
3
4
5
6
7
8
9

function()

{
var StringInclUmlaute = “{{String with umlauts}}”;
var LowerCaseIncUmlaute = StringInclUmlaute.toLowerCase();
LowerCaseExcUmlaute = LowerCaseIncUmlaute.replace(/ä/g, ‘ae’);
LowerCaseExcUmlaute = LowerCaseExcUmlaute.replace(/ö/g, ‘oe’);
LowerCaseExcUmlaute = LowerCaseExcUmlaute.replace(/ü/g, ‘ue’);
return LowerCaseExcUmlaute;
}

Do you have questions about custom variables or Google Tag Manager?

If you have problems with custom JavaScript variables or need assistance with a Google Tag Manager implementation or training, feel free to contact us!

4.9
Based on 33 reviews
Ein Mann in weißem Hemd lehnt an einer Wand, neben ihm das Rheinwunder Logo
Founder Ralph Grundmann 0228 243 313 53