Create a variable

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.

Before you start

Here are some things to know before you start working with variables:

  • Variables can be used in tags and triggers.
  • You can create a variable in Tag Manager or via dataLayer push in JavaScript.
  • 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 {{variable}}.
  • 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.

Create a variable

To create a variable, follow these steps:

  1. Go to Menu > Tag Manager.
  2. Navigate to Variables.
  3. Click + Create new variable.
  4. Name the variable and click OK.
  5. Select the type of variable.
  6. Choose a type of a variable in Tag Manager.

    Tip: For more, read Types of variables.

  7. Adjust settings for a variable. For example, in a DOM-element type add a CSS selector.
  8. Set up a variable in Tag Manager.
  9. When you’re done, click Save for the variable.
  10. Once you create a variable, you’ll be able to pick it from the list of variables in tags and triggers.

Variable in a tag

A variable on the list in a tag.

Variable in a custom tag

A variable on the list in a custom tag.

Variable in a trigger

A variable on the list in a trigger.
Was this article helpful?

of people found this helpful

Technical Support

If you have any questions, drop us a line at support_SPC@piwik_SPC.pro.

We’re happy to help!