Search code examples
google-tag-manager

Can't access a variable from another variable in Google Tag Manager


I am having trouble reading between variables in Google Tag Manager.

I am able to fetch data from the data layer, but when I try to access this data from another variable I get "undefined".

Then I tried setting a variable as a constant enter image description here

and then reading from this variable enter image description here

But I can't even read a constant value enter image description here

Any idea why this might be the case?

I tried pulling data from the data layer which worked. The initial value is filled out.

Then I tried to access this value from another variable using {{Variable Name}}, but this value returns "undefined"


Solution

  • I just ran a quick test to reproduce what you have, and I see both of them working just fine like expected on every event:

    enter image description here

    you have a problem in your testing somewhere. Like maybe you're looking at a wrong container? Wrong enviornment? Forgot to save code changes?

    Oh! There's one more thing! CJS in GTM (and other TMSes) require CSP to allow unsafe-eval. Because all CJS is executed with eval. Without unsafe-eval, all CJS variables will always return undefined. That's most likely your issue. Ask your devs about it. You can read more about GTM and CSP here.