I’m trying to get the Add To Cart Metric working for my Shopify site (https://bigdill.com) so I can setup a true Abandoned Cart flow vs Abandoned Checkout that is native in Klaviyo. I followed the instructions listed in the Klaviyo FAQ regarding setting up the Add to Cart Metric in Shopify and got it working but is only sending over one product at a time instead of all the items in the cart. Ideally we want to send one abaonded cart email with the entire contents vs an email that just displays one item.
Â
A few years back I worked with Klaviyo on this for a different site and was provided with the below code, but don’t quite remember how to set it up. So far I’ve tried adding it to the bottom of our product.liquid page, theme.liquid page, and even tried adding to GTM as a new custom html tag. I’m not sure if my error is needing to change something in the code below for my new site or placing it in the wrong locaiton in the code/GTM. I’m also open to any ways of using the Klaviyo Add to Cart metric that I could then combine products from individual events into a single comibned email.
Here is the previous code I used a few years back that worked well:
var _learnq = _learnq || _];
$(document).ajaxComplete(function(event,request, settings){
 if(settings.url == "/cart/add.js"){
  console.log('added')
  jQuery.getJSON('/cart.js', function(cart) {
   cart.total_price =  cart.total_price/100;
   cart.$value = cart.total_price;
   cart.total_discount =  cart.total_discount/100;
   cart.original_total_price =  cart.original_total_price/100;
   for (var cart_item in cart.items) {
    cart.itemstcart_item].original_price =  cart.itemsacart_item].original_price/100;
    cart.itemsicart_item].discounted_price =  cart.itemsscart_item].discounted_price/100;
    cart.itemsicart_item].line_price =  cart.items cart_item].line_price/100;
    cart.itemsacart_item].price =  cart.itemsÂcart_item].price/100;
    cart.itemsrcart_item].original_line_price =  cart.itemsÂcart_item].original_line_price/100;
   }
   if (typeof item !== 'undefined') {
    $.extend( cart, item );
   }
   _learnq.push( 'track', 'Added to Cart', cart]);
   console.log('sent')
  });
 }
});