SO I'm trying to capitalize the first letter of my string and make the rest lower for a GTM JavaScrip Macro variable.
But it doesn't work. When testing on normal HTML page it does work.
My code:
function() {
var categoryUpper = {{Click Text}};
function firstLetterCapital(cat) {
return cat.charAt(0).toUpperCase() + cat.slice(1);
}
return firstLetterCapital(categoryUpper);
}
Does anyone know how to capitalize first letter in GTM variable?
function() {
var txt = {{Click Text}};
return txt.replace(/\w\S*/g, function(t){
return t.charAt(0).toUpperCase() + t.substr(1).toLowerCase();
});
}