How to refer User-defined variables in Custom JavaScript

I create a user-defined variable var1, and I’d like to use it in another user-defined variable (Custom JavaScript) var2.
How should I refer var1 in the code of var2?
I try to use {{var1}} but it won’t work.
image

And I can’t find ways to call it in the object MatomoTagManager.


I mean, I can see the variable I want in it but it cannot be called anyway.

Does anybody know about this? Or is there other ways to do this?
Thank you so much.

Hi,

Exactly the same issue.
In my case, I would like to use {{ClickElement}} in my Custom JavaScript variable and I have the same error in the Web console.

JavaScript error from Tag Manager can break the previewer?

Any update?

Hi lsittler,

{{ClickElement}} is a Pre-configured variables, I somehow figured out some workaround for them.
You can refer my another post: How to refer a Pre-configured variable in Custom JavaScript

You can use
MatomoTagManager.dataLayer.get(“mtm.clickElement”)
or
MatomoTagManager.dataLayer.values[“mtm.clickElement”]
to get the values of these Pre-configured Variables.

1 Like