I'm working on a custom java script variable for tag manager to track the navigation of my page. The script is only working for the very first element of the kind because of document.queryselect. document.queryselectAll is naturally not solving the problem. It would be great if you could help me:
function(){
var elem = {{Click Element}};
var menu = document.querySelector("ul.nav.meta-nav.justify-content-end");
if(menu.contains(elem)){
return "nav_header";
};
var menu = document.querySelector("div.product-item");
if(menu.contains(elem)){
return "itemlist";
};
var menu = document.querySelector("a.btn");
if(menu.contains(elem)){
return "cta_button";
};
var menu = document.querySelector("footer.footer*");
if(menu.contains(elem)){
return "footer";
}
return "other";
}