Skip to main content
Solved

How to Create a Custom "Added to Cart" & "Viewed Product" Event for Magneto2

  • January 19, 2021
  • 5 replies
  • 1765 views

Forum|alt.badge.img+7

Hi,

Does anyone have the snippet of code that is need for the added to cart & viewed product event for Magneto. I can find shopify and Bigcommerce.

 

Many thanks

Dave

Best answer by Paul S

Hi @davemanson 

 

So the reason you’re able to find documentation for Shopify and BigCommerce Added to Cart and Viewed Product but not Magento is that we do not have a built-in or copy-paste Added to Cart snippet for Magento.

 

Even though we don’t have something that can be copied and pasted like for Shopify or BigCommerce, you can still get this set up but this is something that the business will need to set up using our Javascript Track API.

The process (and most likely the snippet you’re looking for) is similar to the process for Shopify and BigCommerce meaning listening for a person clicking on the “add to cart” button and then sending the Viewed Product payload as an Added to Cart event.

 

I would definitely recommend passing this information along to whatever developer resources you have available so that they can take a look and get this set up. 

5 replies

Forum|alt.badge.img+10
  • Klaviyo Employee
  • 101 replies
  • Answer
  • January 20, 2021

Hi @davemanson 

 

So the reason you’re able to find documentation for Shopify and BigCommerce Added to Cart and Viewed Product but not Magento is that we do not have a built-in or copy-paste Added to Cart snippet for Magento.

 

Even though we don’t have something that can be copied and pasted like for Shopify or BigCommerce, you can still get this set up but this is something that the business will need to set up using our Javascript Track API.

The process (and most likely the snippet you’re looking for) is similar to the process for Shopify and BigCommerce meaning listening for a person clicking on the “add to cart” button and then sending the Viewed Product payload as an Added to Cart event.

 

I would definitely recommend passing this information along to whatever developer resources you have available so that they can take a look and get this set up. 


Forum|alt.badge.img+7
  • Author
  • Active Contributor I
  • 11 replies
  • January 20, 2021

Brilliant thank you


Omar
Partner - Platinum
Forum|alt.badge.img+46
  • 2025 Champion
  • 495 replies
  • January 21, 2021

@davemanson additionally if you have GTM with Google Analytics setup you could leverage the same data to send an event to Klaviyo (using GTM).

If not it's basically triggering a script when someones clicks on the add to cart button that sends related information (product info) to Klaviyo using what @Paul S mentioned.


Forum|alt.badge.img+1
  • Contributor I
  • 1 reply
  • January 27, 2021

Brilliant thank you

How did you achieved that? i also want to do something similar like that.


Forum|alt.badge.img
  • Yes, this is a known behavior in Magento where system URLs get passed to Klaviyo instead of the proper SEO-friendly URLs.

  • Magento by default generates both system paths and rewritten SEO URLs, but sometimes integrations only pull the system path.

  • The support is partly correct—many Magento users do face this, especially when using email marketing tools like Klaviyo.

  • The SEO issue here is that system URLs (e.g., /catalog/category/id/6) are not optimized for search engines or user experience.

  • Manually editing the URL in the Klaviyo email template is one workaround, but it’s not scalable for large catalogs.

  • A common solution is customizing the integration so Klaviyo pulls the URL rewrite table (which stores Seo car park site URLs).

  • You can check Magento’s URL Rewrite Management in admin to confirm the correct SEO-optimized links exist.

  • Developers often use Magento’s getProductUrl() function instead of system paths to ensure SEO links are retrieved.

  • This matters because emails with poor URLs can reduce click-through rates and negatively impact SEO performance when shared.

  • If you’re serious about SEO optimization, ensuring that all marketing channels use clean, human-readable URLs is essential.

  • Some Magento-Klaviyo users add middleware or extensions to automatically replace system URLs with SEO-friendly product links.

  • In short: yes, others have encountered this, but with the right SEO customization, you can make Klaviyo pull the proper rewritten URLs instead of editing them manually.