I’m creating a GTM custom variable template to replace custom js variables with it – to be able to run analytics on more strict CSP. I need my template’s code to use other variables – both dataLayer and GTM built-in ones – to build it’s value.
For data layer I can use (don’t like it, but it’s possible) copyFromDataLayer
API. But what about built-in variables like Page Hostname
? What about using other variables?
I’ve tried to use fields. Creating a text field, allowing it a default value and setting to something like {{Page Hostname}}
. Also, I’ve added a field with the default value 8
– hoping to get at least static value… But data
object in my code always has only gtmEventId
property!
I can see community templates using fields, I see 5 years ago added variable, using fields and even cycling through a data object like this:
for (let key in data) {
if (!data[key]) { data[key] = '-'; }
}
And it goes through all defined fields! But my variable can’t see any field.
P.S. running a preview mode and triggering some events related to this variable on a test website. I see the code is running, logging some stuff to console, etc.