Looking for help with a JavaScript variable code in GTM that acts like a data layer variable. My current code isn't functioning in GSM, can you spot the issue?
function() {
var result = null
if (dataLayer[dataLayer.length - 1] == undefined) {
result = 'undefined'
} else {
result = dataLayer[dataLayer.length - 1]['eventCategory']
}
return result
}
Objective: Ensure data layer variable and custom JavaScript variable work interchangeably in GTM