Solved

Installing Add To Cart Code

  • 30 November 2022
  • 5 replies
  • 544 views

Badge +1

Hi! I am having trouble trying to integrate the added to cart snippet into my code. It is a metric that tracks when people add to cart. I am currently following the tutorial that Klaviyo suggested: https://help.klaviyo.com/hc/en-us/articles/115001396711#create-the--added-to-cart--event2

Here are some screenshots:

 

icon

Best answer by Brian Turcotte 1 December 2022, 22:10

View original

5 replies

Userlevel 7
Badge +36

Hi @peterialshop and welcome to the Community!

 

Just to clarify where you are in this process, what is the main point of trouble you are experiencing? (i.e. you’ve pasted the snippet but it’s not tracking anything, you don’t know where to paste, Shopify can’t validate the code, etc.) It might be helpful for myself and other Community members to understand the issue with some more context about where you’re stuck. 

 

One thing that is important to understand is that you must have Klaviyo onsite tracking enabled and the user must have been previously cookied by Klaviyo for the event to be tracked, so if you are testing the metric without these prerequisites established, nothing will appear in Klaviyo.

 

Here are some other Community threads regarding the Added to Cart metric that might help provide clarity:

 

I hope this helps, and thanks for using the Community!

 

- Brian

Badge +1

Hi Brian,

The metric isn’t tracking when people are adding items into their cart. I have tried to force an add to cart using incognito but still doesn’t work. I was wondering if maybe my code that I had modified and input was incorrect or something, I have read over the Klaviyo guide many times yet I am still can’t get it. 

This is the modified script that I pasted into the theme.liquid file

I am using the theme debutify.

This is the id notation of my site’s add to cart button

This is the snippet off code that I used:

{% if product %}
<script type="text/javascript">
var _learnq = _learnq || [];
    document.getElementById("AddToCart--template--15445490532397__main").addEventListener('click',function (){
         _learnq.push(['track', 'Added to Cart', item]);
    });</script>
{% endif %}

 

Please help me,

Thank you

Badge +1

Hey  @Brian Turcotte ,

I was wondering if you saw my reply? Any help in the code is appreciated!

 

Thanks Peterial

Userlevel 7
Badge +36

Hi @peterialshop,

 

There could be two issues going on here. The first is that the Added to Cart metric only works if the user has been cookied, which means that they’ve entered their email on your store at some point. Therefore, using a private browser to test the metric wouldn’t work. 

 

Additionally, I noticed that your Button is using the Class notation - have you tried the third snippet option for buttons with redirects defined by class notation? This is similar to what my colleague said in the below post:

https://community.klaviyo.com/metrics-and-analytics-36/how-to-add-add-to-cart-snippet-with-shopify-turbo-theme-488

 

If you need more hands on assistance on getting this resolved, I would recommend reaching out and working with a developer you’re familiar with, or with an official Klaviyo Partner.

 

I hope this helps, and thanks for using the Community!

- Brian

Badge +1

@Brian Turcotte ,

Thank you so much for all the help I appreciate it! I had just activated my metric!

Reply