Looking for ready-built or copy-and-paste snippet for "Added to Cart" tracking on WooCommerce site?

  • 3 February 2021
  • 3 replies

Badge +2

Hi everyone,

I hope you’re all doing well in the New Year!

I’m reaching out here because I have a WooCommerce site and just integrated it with Klaviyo but discovered that there is no ready-built or copy-and-paste snippet for "Added to Cart" tracking. As a result, I’m being told that in order to create this metric/event and pass information to Klaviyo, I'd need to create a custom API event using Shopify’s JavaScript Track API.

So all that said, I’m trying to find out if anyone on here knows how to do this or has accomplished this and if so, how?

I’m not a dev or a techie - just trying to get some context for my dev so he can build whatever necessary to add this particular flow.

Thanks in advance!





Best answer by retention 3 February 2021, 06:40

View original

3 replies

Userlevel 7
Badge +57

@Shadylady Hey Charles, welcome to the Community.

The reason why I think there isn’t a cut and dry “Copy/Paste” code with WooCommerce is simply because WooCommerce (Wordpress) is so customizable (with multiple versions) that I think there isn’t exactly one way to do it based on how your particular instance of WooCommerce is setup.  It’s kind of the trade-off between a “highly opinionated” framework (like Shopify or BigCommerce) versus a totally open ended platform like Wordpress.  

If you want the general idea, you can send “any” Events into Klaviyo from the client side via the Klaviyo Javascript API.  “Added to Cart” uses the same methodology as any event you would send to Klaviyo - you set an “Track Event” and pass in any associated data of that Event to Klaviyo via Javascript - in this case, whenever someone “Adds to Cart” which is typically a “Button” on your site that’s triggered onClick(). 

However, some sites have other unique implementations to “Add to Cart” (Links? Checkbox to add multiple things to cart?, Ajax Triggered to Load a SideCart? Submit to a page to handle Add to Cart with other business rules? A 3rd Party plugin that triggers and Add to Cart, etc) so it’ll vary based on how you “Add to Cart” is implemented on your Wordpress Theme.

To generalize, for “Added to Cart” event, normally you would pass an event labelled “Added to Cart” along with all the details (key/value) pairs of all relevant information of the item so you can use them in your Email Template when the Event occurs:

  • Item ID
  • Image URL
  • Product Name
  • Product URL (slug)
  • SKU
  • Price
  • Categories
  • Tags
  • Discounted Price?
  • Variant Details (Color? Size? etc)
  • Product Description?
  • (Bonus) List of Other Cart Items?

You can have your Developer reference these articles to get started:

The Shopify “Added to Cart” depends on the same script from the “Viewed Product” Event - so you can borrow some of the ideas and implementation detail there as well: 

Hope this helps, if not, perhaps a WooCommerce/Wordpress developer can share a common code or snippet that can get you started here in the community!

Badge +2

Hi, thank you so much for the warm welcome and response!

Even for a non-techie like myself, your response makes complete sense so thank you for taking the time to explain it and break it down for me. I really appreciate it!

I will pass this on to my developer in hopes he’ll know how to act on it but in case he has any issues, are you able to recommend any agencies or freelancers that could help me with this?

Thank you again! :) 

Badge +3

Hey @Saha Self-care We developed the Klaviyo Toolkit plugin that passes the Add to Cart event from WooCommerce to Klaviyo.