Variables in Google Tag Manager: Things To Remember

Tags, triggers, and variables in Google Tag Manager are the three main things. Tags are various functions which can track visitor, inject something to website’s code, display a popup, etc, however Triggers are rules which define when tags should be fired.

What about variables? Variables are little pieces of information which can be used both in Tags and Triggers. For example, Page URL. We can use it as a trigger (e.g. fire Google Analytics Tracking code when Page URL contains “/successful-order”) and we can also pass its value along with Google Analytics event tag to Google Analytics servers.

7 tips on how to insert variables in Google Tag Manager correctly

1. All inserted variables are surrounded by double curly brackets {{ }}

No matter where we see these brackets (either in a tag, trigger, or whatever), we can be 100% sure, it’s a variable.

2. We can insert variables in any field which has a LEGO brick button next to it

GTM developers have made it clear to understand where variables can or cannot be used in their interface, so we don’t have to guess. If there’s a button with a LEGO brick next to it, then we’re covered! Go ahead and insert variables.

By the way, we’re not limited to inserting just one variable. If you need, go ahead and add two or five, whatever makes sense to you!

3. Can insert a variable in Custom HTML tag or Custom JavaScript variable by surrounding it with {{ }}

This one is related to point number 1, where all variables in the interface are surrounded by double curly brackets. Custom scripts are also no exception. If you see a script in GTM which contains {{something like this}}, then you’ve just found an inserted variable.

4. If we change variable’s name, GTM will find all references to it (within a container) and rename them as well

Here is the situation, we have a variable which is used in at least two or three triggers and in some tags too. What would we do if, for some reason, we are required to change the variable’s name?

Normally, we have to:

  1. Change the name in variable’s settings
  2. Then search in every corner of GTM container and manually change names of that {{inserted variable}}

Google Tag Manager has this awesome and time-saving feature which checks all current insertions of a particular variable and once we rename the variable in its settings, GTM scans all places (within a container) and changes the name accordingly.

5. GTM will not allow to preview/publish container if it contains an unknown variable

Another feature which prevents marketers and analysts from making mistakes. If we have inserted a variable anywhere in the container for example in tag, but that variable is nowhere to be found in Variables section of our GTM account, we’ll get an error once we hit the Preview or Publish buttons.

The error is pretty informative therefore we’ll be able to solve it fast after that.

6. We can use a variable within a variable

We are not limited to use variables only in tags and triggers, variables can also contain other variables.

Few examples: Lookup table, Regex Table, Google Analytics Settings Variable.

7. Not all variables will work if JavaScript is disabled in a browser

Here is a bit longer list of variables which will not work in Custom Image tag if JavaScript is disabled:

  • Auto-event variables,
  • 1st-party cookie variables,
  • Custom JavaScript variables,
  • JavaScript variables,
  • Data Layer variables,

Variables which will work in Custom Image Tag when JavaScript is disabled?

Here are some of them:

  • Default URL variables (like Page URL, Page Path, etc.),
  • Custom URL variables (e.g. utm_campaign),

Similarly are there any tricks you have used to insert variables in Google Tag Manager? Do let me know.

Need help with Digital Analytics? Get in touch: