Solved

Added to cart snippet not working

  • 4 February 2021
  • 6 replies
  • 240 views

Badge +2

Hey there,

I’m having an issue installing the added to cart metric.
 

The alternative snippet with class notation solution has not worked for me either.
 

Any ideas why this is happening?

 

this is the code from shopify
this is the code from my website

 

icon

Best answer by David To 20 April 2021, 20:56

View original

6 replies

Userlevel 7
Badge +60

Hey @adnansandhila,

This really depends on if you integrated your Shopify account before or after April 19, 2022. 

On April 19, 2022, Klaviyo released an app embed for the Shopify Theme Editor that enables both Active on Site and Viewed Product tracking. The app embed is the newest and easiest way to enable Klaviyo onsite tracking for Shopify. All Shopify users, including those who integrated Klaviyo with Shopify before the release, are encouraged to enable it. The app embed is available to both Shopify stores on vintage themes, and stores on Shopify 2.0 themes.

You can learn more about this from our How to enable onsite tracking for Shopify Help Center article. 

This means, if you integrated after April 19, 2022, all you’ll need to do is enable the Klaviyo app embed which would automatically allow Klaviyo to embed both the Klaviyo onsite and viewed product snippets. 

If you integrated before April 19, 2022, you would have installed the viewed product code within your product.liquid template or theme.liquid template depending on the template you’re using. 

Since you’re getting an error for “item” is not defined, I would suggest reviewing your site code to see if there were any additional coding conflicts. Especially if you integrated after April 19 and already enabled the Klaviyo app embed. 

I would advise reaching out to a developer for more assistance on this review. If you need an introduction to a developer, we have a large network of Klaviyo Partners who can certainly lend a helping hand. 

David

Hi @David To 

referring the first bullet from your response above, i.e “

how and where can we verify that? i mean where is that code supposed to be shown in product template file or where?

I am adding add to cart snippet in theme.liquid file and the error it shows is “item” is not defined. i guess i need to define the item too, can you please elaborate on that? Thank you

Userlevel 7
Badge +60

Hello @joshkalms

Building on top of what @retention had already mentioned, when testing by adding the product to your cart with that code installed, can you confirm the following:

The reason we recommend double-checking these is because the Add to Cart code works in conjecture with the Viewed Product code so if either of these codes were not installed or not installed correctly, it would effect how the Add to Cart code functions; or the lack of functionality. Similarly, both the Viewed Product and Add to Cart code can only be triggered so long as your browser is cookied which would be how Klaviyo identifies the contact who triggered these events. 

 

-David

Userlevel 1

Try adding the name of the class to your script without the . before the class name,

 

 

Badge +2

@retention 

Yes, the snippet is not appearing in Klaviyo and I have tried adding an item to cart but still to no avail...

Userlevel 7
Badge +57

@joshkalms 

From your screenshots I’d say that everything looks good in the snippet.

I assume that by “Not working” you mean that the metric “Add to Cart” has not appeared in Klaviyo.

Have you tried adding an item to cart and see if the metric “Add to Cart” will appear in Klaviyo?

Reply