A variable is used to store information that can be accessed by Tag Manager. For example, a variable
page URL holds and passes information about the URL of the current page.
In Tag Manager, you can use ready-made variables, such as a page URL, page path, referrer, and more. Or, you can create your own variables.
In this article, we’ll show you how to create a variable.
Here are some things to know before you start working with variables:
- Variables can be used in tags and triggers.
- A variable created via dataLayer push can be used only in custom tags.
- A variable is written as a text wrapped in double curly braces
- A variable is often used to store API keys to make them available for tags.
- Variables are also used to capture and pass additional information from your website. For example, the name of the author of the blog post.
To create a variable, follow these steps:
- Go to Menu > Tag Manager.
- Navigate to Variables.
- Click Add new variable.
- Name the variable.
- Select the variable type.
Tip: For more about variable types, read this article.
- In Variable settings, adjust settings. For example, in a DOM-element type add a CSS selector.
- When you’re done, click OK for the variable.
- After creating a variable, you’ll be able to select it from the list of variables in tags and triggers.
Variable in a tag
Variable in a custom tag
Variable in a trigger