Create a Custom "Add 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.

Please note that you must already have Viewed Product tracking installed in order for the Add to Cart event to function properly. You can paste the code (shown below) underneath the Viewed Product code in your product.liquid theme.


"AddToCart" may need to be changed depending on the ID of the Add to Cart button of your product page.
<script text="text/javascript">
	var _learnq = _learnq || [];
	document.getElementById("AddToCart").addEventListener('click',function (){
 		_learnq.push(['track', 'Add To Cart', item]);

This event functions similarly to the Viewed Product event in that each item someone adds to their cart will trigger a new event. So, if you build a flow triggered by the Add 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 an abandoned cart flow that's 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 the Add to Cart flow.

Was this article helpful?
9 out of 14 found this helpful