Facebook Dynamic Product Ads Pixels (Add to cart, success) - Magento

Facebook Dynamic Product Ads Pixels (Add to cart, success) - Magento

August 21, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Facebook Dynamic Product Ads Pixels (Add to cart, success) - Magento

Setting Up Facebook Dynamic Product Ads Pixels in Magento

Facebook’s Dynamic Product Ads are an excellent way to retarget users who have visited your Magento store but haven’t made a purchase yet. To set up the “Add to Cart” and “Success” pixels correctly, follow these steps:

Configuring the Add to Cart Pixel

The add-to-cart event tracks when a user adds a product to their cart. Here’s how you can configure it in your Magento checkout page (cart.phtml):

fbq('track', 'AddToCart', {
  content_name: 'Shopping Cart',
  content_ids: [<?php echo $this->getQuote()->getAllItems(); ?>],
  content_type: 'product',
  value: <?php echo $this->getQuote()->getGrandTotal(); ?>,
  currency: 'USD'
});

Replace the bolded parts with the following:

  • content_name: You can keep this as “Shopping Cart” or use a more descriptive name like “User’s Shopping Bag”.
  • content_ids: This should be an array of product IDs in your cart. In Magento, you can get all items from the quote using $this->getQuote()->getAllItems();.
  • value: This is the total value of the items in the cart. You can use $this->getQuote()->getGrandTotal(); to get this value.
  • currency: Specify the currency used on your site.

Configuring the Success Pixel

The success event tracks when a user completes a purchase on your site. Configure it in your Magento order confirmation page (onepagecheckout/success.phtml):

fbq('track', 'Purchase', {
  content_name: '<strong><?php echo $this->getOrder()->getShippingMethod(); ?></strong>',
  content_category: '<?php echo $this->getOrder()->getCategoryName(); ?>',
  content_ids: ['<?php echo $this->getOrder()->getId(); ?>'],
  content_type: 'product',
  value: <?php echo $this->getOrder()->getGrandTotal(); ?>,
  currency: 'USD'
});

Replace the bolded parts with the following:

  • content_name: This can be the name of the shipping method used for this order.
  • content_category: You need to define your own way to get the category name from the order. In many cases, it’s not directly available without custom logic or additional fields in the database.
  • content_ids: Here you can use the unique ID of the order as the content id since it represents a single transaction.
  • value and currency: Similar to the add-to-cart pixel, these values are obtained from the order object.

Conclusion

Setting up Facebook’s Dynamic Product Ads pixels in Magento requires understanding how to extract data from your quote and order objects. The provided PHP snippets demonstrate how to replace the bolded parts with relevant Magento variables.

Remember that the actual implementation may vary based on your theme and specific requirements. Always test these changes thoroughly before deploying them to a live site.

For more detailed guidance on integrating Facebook pixels with e-commerce platforms like Magento, check out our comprehensive guide at Laravel Company.

Happy coding!

Checkout Catalog Themes Configuration

Our network