Solved

Need help creating an "Added to Cart" event for Shopify (Theme "VOGUE")

  • 26 October 2023
  • 1 reply
  • 54 views

Badge

Hi! Im wondering if someone could please help me.

I am using Shopify’s “VOGUE” theme and can't seem to create the “added to cart” event for Klaviyo. I have been using this article in trying : https://help.klaviyo.com/hc/en-us/articles/115001396711

In this article, I use snippet 3 under the “theme.liquid” section (using class notation). Here is what shows up with I “inspect” my add to cart button on my website:

<input type="submit" class="button product-add-available pn-button-5a1rxhfa4yq" value="Add to cart">

Thus I hope I correctly assumed that I should use snippet 3 in the above article, using class notation.

This is what it looks like when I try to code it in:

{% if product %}

<script type="text/javascript">

var _learnq = _learnq || [];

  var classname = document.getElementsByClassName("button product-add-available pn-button-p3ysqtfmy99");

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>

  {% endif %}

I still cannot seem to get it to work =(. Could someone please help me? Maybe it has something to do with my theme on Shopify. I would really appreciate it! 

Thank you in advance

Katarina
 

icon

Best answer by Taylor Tarpley 27 October 2023, 16:47

View original

1 reply

Userlevel 7
Badge +60

Hi there @kat99

 

Welcome to the Community! Happy to help!

 

Great job so far identifying that your button is class notation! 

 

Two things that might be the issue here is:

  1. It seems that the code in your ATC script for you button code “button product….p3ysqtfmy99” doesn't match the end of your button’s code, which seems to be "button product…..5a1rxhfa4yq”
  2. I would ensure that the placing of the script is at the bottom of your “theme.liquid” section and following this image below for how all the code should be formatted and in the proper place.

 

Finally, I’d check out these similar threads to gain more insight!

 

Hope this helps!

-Taylor 

Reply