I am currently facing an issue with a JavaScript script I have implemented to track button clicks on my website and send information to Klaviyo. I have set up a flow in Klaviyo to send emails based on the button click "Add To Wishlist," but for some reason, it is not functioning correctly.
Following advice from this post on Stack Overflow: getElementsByClassName() with two classes
Since I have 2 classes, I have used a query selector. Here are screenshots of them: 1. On Collection Page http://prntscr.com/rn50ok
2.On Product Page: http://prntscr.com/rn51n0
P.S
Although this may seem basic, I have very limited knowledge of JavaScript and APIs. I merely followed Klaviyo's documentation and attempted to create the code based on their Add To Cart example.
<script text="text/javascript">
var _learnq = _learnq || [];
var classname = document.querySelectorAll(".yith-wcwl-add-button jas_add_wishlist,.add_nitro_wishlist add_to_wishlist gecko-tooltip");
var myFunction = function() {
_learnq.push(['track', 'Add to Wishlist', item]);
};
for (var i = 0; i < classname.length; i++) {
classname[i].addEventListener('click', myFunction, false);
}
</script>