Why is my Klaviyo add to cart events firing off at random times / incorrect?

It is common that your add to cart events invalid, due to a Klaviyo bug in the add to cart tracking code installed onto Shopify stores before July 2024. This will result in add to cart events being fired with no items, or with a price of 0. You may also experience events being sent for customers that haven't actually added to cart.

The way you can identify that this issue affects you, is to look at the Added to Cart event data being sent to Klaviyo.

Notice that items are empty, and total_price is 0. This indicates that this is an invalid add to cart event.

Why is this happening?


On your Shopify store, you would have added the following code to product pages to support add to cart tracking (provided as part of Klaviyo documentation, which is located here)

if (`${window.location.origin}/cart/add.js`
.includes(res.url)) {
addedToCart()

}

The code is incorrect as it will run even when a customer hasn't added an item to cart. This results in the "addedToCart()" line of code being executed erroneously, e.g. on page view.

Klaviyo has recently updated their documentation to resolve this issue, but for merchants that onboarded onto Klaviyo before July 2024, this issue continue to be present.

In Klaviyo's documentation (as of 4th July, 2024), it specifies the code should actually be

if (`${window.location.origin}/cart/add.js`
.includes(res.url) && res.url !== '') {
addedToCart()
}

Note the addition of the && res.url !== '' code in the code provided by Klaviyo.

Without that check, duplicate, unnecessary add to cart events will be sent through for the non-Audiences Add to Cart (ATC) event.

What do I do to resolve this issue?


To prevent errenous / inaccurate add to cart events being fired, as well as prevent potential double sends as a result, please update your Klaviyo snippet to match the latest Klaviyo documentation.

The newest snippet is located under "Add the snippet to your site"