Click Tracking not executed - Further Troubleshooting
document.addEventListener('click', function(event) {
// This function will check if the event target or any of its parents
// match the given selector.
function matchSelector(target, selector) {
// Loop through the parent nodes until the document is reached.
while (target && target !== document) {
// Check if the current target matches the selector.
if (target.matches(selector)) {
return target;
}
// Move up in the DOM tree.
target = target.parentNode;
}
return null;
}
// The selector for your specific element
var selector = 'a[href*="Rent-a-Truck"]';
// Check if the clicked element or any of its parents match the selector.
var match = matchSelector(event.target, selector);
if (match) {
// Call your function here.
console.log('Link with "Rent-a-Truck" in href clicked.');
// You can replace this log with your function to be executed.
}
});Last updated
Was this helpful?