Create a Custom "Added to Cart" Event for Shopify



Klaviyo tracks a Checkout Started event from Shopify when a shopper enters their email address and shipping information ("Customer information") on the first page of the Shopify checkout process and clicks continue ("Continue to delivery method"). This metric is included in the Klaviyo/Shopify integration and does not require any additional work to set up.

If you would like to track an event as soon as a shopper adds an item to their cart, you can do this by adding a line of Javascript to your Shopify store's product.liquid theme file.

Once you get your custom "Added to Cart" metric syncing, head to the Klaviyo Flow Library to find a pre-built Abandoned Cart Reminder flow that's built using metric.

Please note that you must already have Viewed Product tracking installed in order for the Added to Cart event to function properly.

The Snippet

Paste this code directly underneath the Klaviyo Viewed Product snippet in your product.liquid theme:

<script text="text/javascript">
	var _learnq = _learnq || [];
	document.getElementById("AddToCart").addEventListener('click',function (){
 		_learnq.push(['track', 'Added to Cart', item]);

"AddToCart" in the  getElementById statement may need to be changed depending on the ID of the Add to Cart button of your product page. This snippet will watch for the "add to cart" button element submitting, and track an event when someone clicks this element.

This event functions similarly to the Viewed Product event, in that each item someone adds to their cart will trigger a new event.

If you build a flow triggered by the Added to Cart event, make sure to add a condition to the flow that will prevent shoppers from being bombarded with emails each time they add an item to their cart. Additionally, if you also send a traditional Abandoned Cart Reminder flow that is triggered by the Checkout Started event, you'll want to add another filter to the flow to make sure that people who trigger this second flow do not get your Added to Cart flow.

For example, in the following screenshot, the flow trigger includes 3 filters:

  • Someone has not placed an order since starting this flow.
  • Someone has not started a checkout since starting this flow.
  • Someone has not been in this flow in the last 30 days.

Was this article helpful?
19 out of 39 found this helpful