I am setting up a GTM variable, and I thought this error only came up when you don't wrap all of the code in a function.
Here is my code:
function VIN() {
let vins = document.getElementsByClassName("xyzClass").innerText;
let targetVIN;
for (var i = 0; i < vins.length; i++) {
if (vins[i].innerText === "VIN") {
targetVIN = vins[i].nextSibling.innerText;
}
}
return targetVIN;
});
GTM is throwing the error in the title in reference to line 2 character 2.
I'm a noob, what am I doing wrong here? Thank you in advance!
This will not work in a variable, since a custom JS variable requires an anonymous function, and yours is a named function.
It will also not work in a custom HTML tag, because GTM does not support ES6 features in custom tags and in variables (although it is partially supported in custom template, but those to do support DOM access).
If you use this in a custom tag, just replace "let" with "var".