So i’ve tried second and third method from this doc as the first one wasn’t working. Both second/third worked with default cart drawer. However, when i installed upcart app for add to cart drawer which disables the default drawer, the add to cart event isn’t triggering in klaviyo.
This is the script i’m using on main-product.liquid in my dawn 12 theme:
<scripttype="text/javascript">var _learnq = _learnq || [];
var classname = document.getElementsByClassName("product-form__submit");
var addToCart = function() {
_learnq.push(['track', 'Added to Cart', item]);
}; for (var i = 0; i < classname.length; i++) {
classname[i].addEventListener('click', addToCart, false);
}
</script>
It’s working fine with default shopify drawer but not with upcart drawer.
I also read another post related to this topic but that said to change the endpoint in the script from /cart/add.js to /cart/add.js?upcart=1 but i can’t seem to find these endpoints in my script.
Best answer by StefanUE
@Daddy hey, thanks for your question and welcome to the community!
You’ve installed Snippet 3, is that correct?
Below the instructions on how to implement that snippet, you’ll also find this: This snippet will likely need to be modified, because the Add to Cart variable in the snippet needs to match the class used on your site.
Open up one of your site’s product pages.
Right-click your "Add to Cart" button and select Inspect.
The console will open, showing the source code of your "Add to Cart" button. The following image shows the class of the "Add to Cart" button highlighted in the console.
Compare your button code in between the quotations, highlighted in the above example, with the contents in between the parentheses after getElementsByClassName in the code snippet above. For example, the class listed in the screenshot is btn product-form_cart-submit btn--secondary-accent and the variable listed in the snippet is add-to-cart.
If they don’t match, modify the snippet to match the class of your button. Our example’s modified snippet looks like this:
Perhaps installing Upcart changes the class name in your snippet, so you basically just have to repeat the whole process after switching it on, then trying again to see if it works.
@Daddy hey, thanks for your question and welcome to the community!
You’ve installed Snippet 3, is that correct?
Below the instructions on how to implement that snippet, you’ll also find this: This snippet will likely need to be modified, because the Add to Cart variable in the snippet needs to match the class used on your site.
Open up one of your site’s product pages.
Right-click your "Add to Cart" button and select Inspect.
The console will open, showing the source code of your "Add to Cart" button. The following image shows the class of the "Add to Cart" button highlighted in the console.
Compare your button code in between the quotations, highlighted in the above example, with the contents in between the parentheses after getElementsByClassName in the code snippet above. For example, the class listed in the screenshot is btn product-form_cart-submit btn--secondary-accent and the variable listed in the snippet is add-to-cart.
If they don’t match, modify the snippet to match the class of your button. Our example’s modified snippet looks like this:
Perhaps installing Upcart changes the class name in your snippet, so you basically just have to repeat the whole process after switching it on, then trying again to see if it works.