While you configure some tags or triggers, you may have noticed text fields with such an icon on the right:

Instead of setting a fixed value for a form field, this icon lets you select a so called “Variable”. A Variable allows you to basically use a dynamic value whose actual value will be resolved at the time the value is being accessed, for example this could depend on the current page URL, Referrer, Screen size, or more. If it looks like a great feature, that’s because it is.
For example, instead of defining a hard coded event name “//mypageurl”, you may want to replace the event name with the current page URL path. This means depending on which page URL a user is currently viewing, the event name will be different.

To do this, click the icon on the right hand side and locate the row that says “Page URL Path” and select it. The text field will afterwards look like this:

The curly brackets you see means that they reference a variable with the id “PagePath”.

You can even go a step further and connect multiple variables or add custom text like this:

Preconfigured variables

Matomo Tag Manager comes with a set of preconfigured variables that you can use right away without having to configure them. Whenever you want to use them, you just select them and that’s it.

As you will see the list is quite long.

As an example, let’s imagine that you would like to know if some of your pages are containing several H1 HTML tags, you could then use a variable within the Matomo configuration as shown in the example below:

As a result it will appear like this when a page is loaded:

As you can see in the example above, the variable plays its role by auto-filling our custom dimension.

Preconfigured variables can be very powerful but you can go even further with user-defined variables.

User-defined variables

Besides this, Matomo comes with an equally big set of Variable types that you can configure to your needs. You may want to read the value from a certain HTML DOM element (for example the content of a form), or you want to read the value from a meta tag such as the current language being used, a specific cookie value, or a value from the data layer.

To use any of these variable types, you first have to create a variable, configure the variable, and afterwards you can reference this variable by name and re-use it whenever you need it. Say you have given the variable the name “my own variable name that I created”, then you can reference it like this later:

Don’t worry, you don’t have to remember the name of the variable. You can simply select the created variable by clicking on the icon on the right.
To create such a variable, go to “Variables => Create Variable”, or you can always directly create a variable by clicking on the above text field icon, and then select “Create a new variable”.

Now you’ll see the screen of variable types which explains that you first need to select a variable type:

In this example, we would like to collect the “publishing date”, this variable is defined within a DOM element of the page:

In order to get this data we need to indicate to Matomo the DOM Element we would like to work on. In our specific case, this DOM Element contains a class which has “entry-date published” as a value.

Once created, you just need to associate it with a tag, for example a custom dimension in order to process that data within reports:

If you’re feeling that the possibilities are endless… that’s because they are. And guess what? You can even go further.

Advanced variables settings: Default value & lookup table

Advanced variables settings allows you to go even further within your TMS configuration. In the screenshot example below is a lookup table, you can create a variable which changes according to some conditions:

You can then call this variable within your Matomo tag through the configuration variable:

As a result, you will only need one container to send data to all your websites which will save you heaps of time in terms of tag deployment.