Added to Cart event not working

  • 23 May 2024
  • 1 reply


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:

I see the “Viewed Product” event properly

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 || [];
    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
{% 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:



Best answer by bluesnapper 24 May 2024, 18:28

View original

1 reply

Userlevel 7
Badge +39

Welcome to the community @mateomoreno 

The add-to-cart JS snippet for Shopify you’ve provided does not look correct. 

That standard Shopify one looks like this: and works on Shopify sites I’ve added it to. 

Unless I’m missing something you’re trying to do with a custom event?