Reputation: 25
GTM is returning 'Undefined' when I use the DataLayer Variable call in my JS.
google_tag_manager['GTM-XXX'].dataLayer.get('ecommerce.transaction_id')
and it returns the correct value.dataLayer[5].ecommerce.transaction_id
it also returns the correct value.{{dlv - ecommerce.transaction.id }}
returns 'undefined'. I added a console log to see the output for debug reasons.Here is what the GTM Variable Config looks like:
Upvotes: 1
Views: 1321
Reputation: 8111
Don't use console logs to debug GTM. Use GTM preview.
In GTM preview. select the event at which you expect your variable to appear, go to variables and see its value. It's supposed to be undefined there. Now go to your datalayer and see what's there. The transaction is likely to not be there at the moment of your query. Go through events, see where the dataLayer event push happens. That's where you're supposed to access your variable.
If not, add screenshots from the preview.
Also you should indicate whether this is GA4 EEC DL structure.
Upvotes: 2