The reason I love Shopify is for its simple integration of Facebook Pixel and Google Analytics. You can yourself install the Facebook pixel without hiring an expert. But still, there is an issue with the Facebook add to cart event when it comes to ajax add to cart buttons. 

This is a very serious problem for many Shopify users and I didn’t find a reliable solution on the internet. So I thought of presenting you a simple and reliable solution to fix the issue. 

What’s the issue?

If you are unable to see the Facebook add to cart event, chances are you are using Ajax add to cart button on your site. But how do you know if it’s Ajax? Click on the add to cart button, if the page doesn’t reload on add to cart click, it’s an Ajax button. You will not see the add to cart event firing in the pixel helper. 

How to fix? 

All you have to do is to add a simple add to cart custom code to your Shopify website. Follow the below steps:

1. Log in to your Shopify Account

2. Click on themes under Online Store from the left menu

shopify themes

3. Click on actions >> edit code

edit code shopify

4. Find ‘product-template-liquid’ file using the search and open it

product template page shopify

5. Copy the below code and paste it on the end of the above file

<script type="text/javascript">
$( '.btn--add-to-cart' ).click(function() {
fbq('track', 'AddToCart', {
    value: {{ product.price | money_without_currency }},
    currency: '{{ shop.currency }}',
    content_ids: '[{{ product.id }}]',
	content_name: '{{ product.title }}',
	content_type: 'product_group',
});});
</script>
add to cart event code shopify

6. Save the file. 

Open a product detail page and click add to cart button. You will now see the add to cart event firing.

facebook pixel helper

If you have the add to cart button added on other pages, make sure to add the same code on those pages as well. 
I hope this will work for 99% of the Shopify users. If for some reason this isn’t working for you, you can hire me.

Author

Noman Karim is the founder of MeasureMySite. He is passionate about web analytics and enjoys working with online businesses to help them measure marketing campaigns and website traffic.