<script>
document.addEventListener('DOMContentLoaded', function() {
// Select all elements with the class 'actionbutton'
let actionButtons = document.querySelectorAll('.actionbutton'); // Create trackClick event to capture name and location
function trackClick(event, button) {
event.preventDefault(); // Prevent the default link behavior
let name = button.getAttribute('data-name');
let location = button.getAttribute('data-location');
let href = button.getAttribute('href'); // Get the link's href value // Log the values for debugging
console.log('Tracking button click:', name, location); // Push to dataLayer with just the necessary data
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'event_button',
buttonName: name,
buttonLocation: location
}); console.log('Data Layer pushed:', {
event: 'event_button',
buttonName: name,
buttonLocation: location
}); // Delay the navigation to the link's href by a short time to ensure tracking is done
setTimeout(function() {
window.location.href = href;
}, 300); // 300ms delay should be enough
} // Attach event listeners to each action button
actionButtons.forEach(button => {
button.addEventListener('click', function(event) {
trackClick(event, button);
});
});
});
</script>