Can variable return a function?


(Jesper Ahne) #1

Hi,

In GTM you can use a variable as a function like this;

Var1:
function(){
return function(x, y){return x+y}
}

Var2:
function(){
return {{Var1}}(3, 5);
}

I cant make this work in MTM, is this not supported?

Regards
Jesper


#2

Hi there, just to better understand. What Tag/Trigger/Variable did you want to use and assign a function? And how did you want to use that function afterwards? In a Custom HTML Tag?


(Jesper Ahne) #3

Hi,

I whanted to store a function as a variable to be used on multiple other variables.

Whan digging in the doc´s I found that you have access to parameters and TagManager in all variables and triggers. I see the use of parameters.get(‘matomoConfig’, {}); in the code and matomoConfig is a variable? So I thought that you culd access other variables this way but it seems all custom variables get autogenerated names like ‘CustomJsFunctionVariableb95da7d6’ so this dosent seem to work.

/Jesper


#4

You can certainly use the “Custom JavaScript” variable to store a function and use it in a Custom HTML tag like this:

The variable:

The tag:

If you want to access the matomo configuration it is even easier… simply select the matomo variable in tag manager and assign it to a variable:

You can then directly access eg x.matomoUrl :slight_smile: