Hi Tom,
at the moment it isnāt yet possible to do this, but it is listed in our backlog at: https://github.com/matomo-org/tag-manager/issues/212
but unfortunately as we have not scheduled it yet, we cannot give a date when it will be implemented.
@Trackingninja solution might work as well, have you tried it maybe?
Hi all,
I hit this topic googling matomo javascipt variable function, indeed I encountered the same issue.
As there is a generic solution for the issue described in the link provided by @matthieu, I share it there:
function () {
// Below you must provide your own datalayer property as defined in your container
// OR one of the Matomo defined property as displayed in this example
var propertyName = 'mtm.clickElement'
if (window.MatomoTagManager.dataLayer.get(propertyName)) {
return window.MatomoTagManager.dataLayer.get(propertyName);
} else {
return 'foo';
}
}
An addition to that:
I think itās a little bit more complicated.
Some properties are only available in the datalayer when some triggers listen to them (f.e. clicks or scrolls) and fill the datalayer with them.
But not all pre-configured variables are written in the datalayer.
In my case I want to work with the preconfigured variable {{PreviewMode}}.
I get this with this code, so I think:
var debugMode=window.MatomoTagManager.debug.enabled;
//debugMode= true|false;
Using the TagManager object mostly does wonders, but what is the syntax if i want to use it for a DataLayer variable instead of the āmtm.clickElementā variable ?