Why is my Klaviyo add to cart events firing off at random times / when I don't add to cart?

It is common that your Klaviyo add to cart events / flow may be sending erroneously, due to a Klaviyo bug in the add to cart tracking code installed onto Shopify stores before July, 2024. This unrelated to Instant Audiences.

On your Shopify store, you would have added the following code to product pages.

This would have been provided as part of Klaviyo documentation, which is located here.

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

}

The issue with this, is that the if statement will evalulate to true if res.url is an empty string. This results in the "addedToCart()" line of code being executed erroneously, e.g. on page view.

This issue can result in add to cart events being sent incorrectly, and double sends due to add to cart events being sent before product viewed events (usually, add to cart events should occur after product viewed events). 

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()
}


Screenshot from Klaviyo dashboard as of 4th July, 2024

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 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"