Advantages and possibilities of Custom JavaScript Variables 

Custom JavaScript Variables in Google Tag Manager

Google Tag Manager Tutorial
Ralph Grundmann · Published on 15 March 2022

This article is from our archive and reflects the situation as of March 2022.

Custom variables (especially Custom JavaScript Variables) of Google Tag Manager are a powerful tool to eliminate tracking issues. A variable of the Custom JavaScript type consists of an 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, a custom JavaScript variable takes other variables as input, processes them with JavaScript and returns the result as 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 and return lowercase

1
2
3
4
5
6
7
8
9
10

function()

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

 Personal advice 

Questions about variables in Google Tag Manager?

Do you need help with custom variables, setting up your container or training for your team? We are happy to help.

Request a consultation
SISTRIX-zertifizierte Agentur
Microsoft Partner Badge
4.9
Based on 32 reviews

Reviews from our Google Business Profile. We check every review against our client projects.

 Trends, strategies & insider knowledge for sustainable online success 

In the blog: The latest trends in SEO, SEA, affiliate marketing, and of course from Rheinwunder