I am not sure why the added to cart event is not working.
I have installed the app “Klaviyo Onsite Javascript” on shopify.
My Integration is good:
![](https://uploads-us-west-2.insided.com/klaviyo-en/attachment/f45f3783-9662-4def-bcaa-85bb2462b0a7.png)
I see the “Viewed Product” event properly
![](https://uploads-us-west-2.insided.com/klaviyo-en/attachment/2f6a904d-edc3-4c91-a1c1-536aec575e84.png)
My code is picking up my add to cart button correctly
<!-- Klaviyo add to cart event snippet -->
{% if product %}
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
var _learnq = _learnq || q];
var classname = document.querySelectorAll(".addtocart-button-active");
var addToCart = function() {
_learnq.push('track', 'Added to Cart', item]);
console.log('Product added to cart:', item);
};
classname.forEach(function(element) {
element.addEventListener('click', addToCart, false);
});
}, 2000); // 2000 milliseconds = 2 seconds
});
</script>
{% endif %}
<!-- END of Klaviyo add to cart event snippet →
I added a console.log on the function addToCart, to make sure everything works properly. Everytime I add an item to the cart, my console Log works, meaning, it picks up the button, and it shows me the “item” but it is just not being sent to Klaviyo.
Any help is appreciated, thank you!
This is my console.log item for everytime I click add to cart:
![](https://uploads-us-west-2.insided.com/klaviyo-en/attachment/d76fb918-78e2-497f-8030-4501e6b13dcf.png)