Using built-in GTM Variables in Custom JavaScript and HTML

Google Tag Manager has a lot of built-in variables that are pre-created for you. However, these variables can't be customized which means you have to use them as is. If you do need to add some customization or further processing of these built-in variables then you can create your variables called user-defined variables.

User-defined variables have various types that you can choose from and customize. often such customization might require using other variables. This is where you can use the "Custom JavaScript Variable" type.

 

Which variables can you use in Custom JavaScript Variables?

You can use both built-in variables and user-defined variables in Custom JavaScript variables. You can even use other custom JavaScript variables.  However, built-in variables have to be configured or enabled before you can use them for any tags, triggers, or variables. Enabled built-in variables will be available throughout Tag Manager wherever variable selection menus appear.

How to Enable built-in variables in Google Tag Manager (GTM)

  1. Click Variables in the left side menu.
  2. On the top, you will see the Built-in Variables section. Click on Configure button in this section.
  3. Check the checkboxes next to the variables that you want to enable

 

How to create User-Defined Variables in Google Tag Manager (GTM)

  1. Click Variables in the left side menu.
  2. Scroll down to the User-Defined Variables section. Click on the New button in this section.
  3. Click Variable Configuration and select a variable type.
  4. Add the setting for the chosen variable type.
  5. Give the variable a name.
  6. Click Save.

In this post, we will focus on Custom JavaScript Variable type and use a built-in variable within it.

 

Configuring a Custom JavaScript Variable

  1. Click Variables in the left side menu.
  2. Scroll down to the User-Defined Variables section. Click on the New button in this section.
  3. Click Variable Configuration.
  4. Select Customer JavaScript Variable
  5. Add an anonymous function in this variable (Check out JavaScript and JavaScript applications in Google Tag Manager course)
  6. To refer to any other variable, built-in or user-defined, in your code, type in {{ (two beginning curly brackets).
  7. This will open up a list of variables that are configured and enabled. If a parable does not show up in the list then make sure it is enabled.
  8. Pick the variable that you want to use.
  9. Type in }} (two ending curly brackets).
  10. And that's all this is how you can use another variable in your own Custom JavaScript code within Google Tag Manager.

 

Learn JavaScript for Google Tag Manager

We have developed a complete course for Marketers and Marketing Analysts to learn JavaScript. This course is focused on teaching you the fundamentals and applications in Google Tag Manager. Even though examples are in Google Tag Manager (GTM), you can use them for Adobe Analytics using Adobe Launch as well or any other marketing analytics tools.

 

Other Google Tag Manager posts that might like

Where to get more help with JavaScript, Google Analytics 4, and Google Tag Manager?

Learn and Master JavaScript, Google Tag Manager, and Google Analytics 4

Leave a Reply

Your email address will not be published.