Hey guys, I’m having trouble installing one of the following metrics.
That being added to cart.
On my clients shopify store, I have inspected the element of the add to cart button and even applied both snippets (to testing reasons) for id and class. Obviously I’ve followed instructions to paste the snippet of code under the product.liquid file
For you information, my clients “add to cart” button has a class notation.
However, when I use the alternate code snippet and modify it, still does not show the metric in klaviyo.
I also want to point out that the add to cart button on my clients store is automated to pulse frequently switching from:
class=”ProductForm__AddToCart Button Button--secondary Button--full vtl-aa-animated-atc-button”
class=”ProductForm__AddToCart Button Button--secondary Button--full vtl-aa-animated-atc-button vtl-aa-active”
I believe this is the main reason klaviyo can’t identify the added to cart metric.
If anyone knows anyway to bypass this, or if I am installing the code wrong please message me back.
Since the add to cart button has a class notation this is the code Klaviyo help centre told me to use (yes I have tested without modifying the code also - still to no avail )
var _learnq = _learnq || ;
_learnq.push(['track', 'Added to Cart', item]);
Best answer by retentionView original
The snippet you’ve provided uses “add-to-cart” as the class name. Based on the button code you’ve also provided, it looks like the name of the class is actually “ProductForm__AddToCart” -- as a result, I’d suggest switching the querySelector to use ‘.ProductForm__AddToCart’ or whatever the actual class name is for your Add to Cart button.
Let us know if it worked!
Hey guys! Help me! My add to cart button looks like this. Nothing matches on klaviyo’s article.
Thanks for sharing your question with the Klaviyo Community.
I can see that your button does not have an ID and instead uses a class notation. In this circumstance, you’ll need to paste an alternative snippet of code into Shopify. Maybe you can clarify what you mean by “nothing like this” and “nothing matches on Klaviyo’s article” because our article on Added to Cart does detail the code to use for a button using class here.
If you’re still having trouble logging the Added to Cart event, after reviewing the article, I recommend reviewing the posts from this thread. The last post on the thread summarizes the necessary steps you need to take to successfully log the Added to Cart metric.
Thanks and have a wonderful day.
Hey there, I am having the same problem. It looks as if i have a button id and a class notation. I have tried following the steps both, applying everything i can think of.
can anyone help?
The button code you highlighted actually resembled the example found in the Alternate Code Snippet for "Add to Cart" Button with Class Notation subsection of the How to Create a Custom "Added to Cart" Event for Shopify article Klaviyo offers. Although they are not exactly the same, the same theory would apply since your button is using multiple classes. I would suggest editing and using the base code below in your product page to apply this add to cart functionality:
After customizing and installing the code, I would also suggest testing it by following the below steps which I’ve mentioned in a similar Community post:
If you are still having trouble I would encourage you working with a developer or the Shopify’s theme developer use an ID that's consistent across all product pages, or add a class to all of their product pages (such as "add-to-cart"), so that the metric can be tracked off of a single identifier. You can also finding a Klaviyo partner who can also further help you with this as well.
I hope this helps!
Thanks for your response! I’ve tried what you have recommended but still no luck.
Could you be more specific on what my class notation exactly is?
Also I’ve looked through my other liquid files and cant find anywhere else that would require the code snippet.
I am also a little confused because when I first applied the snippets and was accepted to make the flow, it tracked myself adding to cart once, making me think it was successful but since then it hasn’t worked.
I’ve done a lot of work on this theme and don’t want to have to make a whole new website just for this metric.
The class notation, from your screenshot seems to be
btn btn--full product-form__cart-submit btn--secondary-accent.
If you were able to track an add to cart event, then that would mean that the code you first used and applied did work correctly. Keep in mind that the add to cart event would only be triggered if your browser is cookied. Even if your code was installed correctly but your browser was not cookied and you added an item to the cart, the event would not trigger and track.