{"id":2518,"date":"2024-12-31T20:22:45","date_gmt":"2024-12-31T20:22:45","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/how-to-add-facebook-pixel-to-magento-2-set-up-tracking\/"},"modified":"2025-07-21T11:53:33","modified_gmt":"2025-07-21T06:23:33","slug":"add-facebook-pixel-to-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-facebook-pixel-to-magento-2\/","title":{"rendered":"How to Add Facebook Pixel to Magento 2 &amp; Set up Tracking?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">You can make good marketing campaigns better through data-driven decisions. Facebook Pixel in Magento 2 is a tool that can help you collect data and optimize your Meta ads strategy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But how do you add one? <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s learn through this step-by-step guide on Magento Facebook Pixel.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-facebook-pixel\">What is Facebook (Meta) Pixel?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Facebook Pixel (a.k.a Meta Pixel) is a JavaScript code for tracking data for Facebook Ads campaigns. It\u2019s added to the website\u2019s HTML code and tracks visitors from ad campaigns. The code helps you to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Track conversions<\/li>\n\n\n\n<li>Optimize Meta ads<\/li>\n\n\n\n<li>Remarket ads to visitors<\/li>\n\n\n\n<li>Create targeted audience<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Generally, the Meta Pixel tag is added within the &lt;head&gt; section in the website\u2019s header. Therefore, it appears on all the pages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-get-facebook-pixel-code\">How to Get a Facebook Pixel Code?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First, you\u2019ll need to create a new dataset in the Facebook Events Manager. Then, you can create a Pixel code to track data into it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Log into your Facebook account and go to&nbsp;<a href=\"https:\/\/www.facebook.com\/events_manager\" target=\"_blank\" rel=\"noreferrer noopener\">Facebook Events Manager<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the left menu, click&nbsp;<strong>Connect data sources<\/strong>&nbsp;and select&nbsp;<strong>Web&nbsp;<\/strong>from the list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Click \u201c<strong>Connect<\/strong>\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/1-create-a-new-web-data-source.png\" alt=\"create a new web data source\" class=\"wp-image-51601\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Enter a suitable name for the dataset as per your preferences. It\u2019s used for identifying multiple data sources within the Events Manager and could be anything.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Click the \u201c<strong>Create<\/strong>\u201d button.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, enter the homepage URL of your Magento 2 website and choose&nbsp;<strong>Explore other options<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/2-enter-website-url-for-facebook-pixel.png\" alt=\"enter website url for facebook pixel\" class=\"wp-image-51605\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Next, Facebook will ask if you need guidance with the setup, choose the&nbsp;<strong>Do it yourself<\/strong>&nbsp;method and choose&nbsp;<strong>Meta pixel only<\/strong>.<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/3-choose-how-to-connect-to-your-website.png\" alt=\"choose how to connect to your website\" class=\"wp-image-51608\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Next, two options will be displayed to add meta pixel code to your Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Choose&nbsp;<strong>Install Code Manually<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Facebook Pixel tracking code for the dataset will be displayed on the screen. Click the&nbsp;<strong>Copy code<\/strong>&nbsp;button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/4-copy-facebook-pixel-code-700x439-1.png\" alt=\"copy facebook pixel code\" class=\"wp-image-51611\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once the code is copied, continue and select the events that you want to track and complete the setup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"options-to-add-facebook-pixel\">Options to Add Facebook Pixel in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In Magento 2, you need to add the Facebook Tacking code at the bottom of the header section section inside the &lt;head&gt; tag. You can do this in two ways:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use an Integration Extension \u2013<\/strong>&nbsp;You can use a third-party extension like Meetanshi\u2019s Facebook Pixel for Magento 2 for the integration. It offers you more control over tracking preferences and also works well with custom themes.<\/li>\n\n\n\n<li><strong>Install Code Manually \u2013&nbsp;<\/strong>This method requires you to manually add the Pixel code to the theme\u2019s header. It requires technical expertise and does not offer control over the tracking preferences.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s start with our preferred method for adding FB Pixel to Magento 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"method-1-use-an-extension\">Method 1: Use an Integration Extension<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can use a third-party extension to add the tracking code to your store. For example, Meetanshi\u2019s Magento 2 Facebook Pixel extension is an easy option to do this. It supports setting preferences for tracking conversions in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also use this extension to set up multiple pixel tracking for multiple store views on your website. Here\u2019s the step-wise method on how to add Facebook Pixel in Magento 2 using extension.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-1-install-extension\">Step 1: Install Magento 2 Facebook Pixel Extension<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Go to&nbsp;<a href=\"https:\/\/meetanshi.com\/magento-2-facebook-pixel.html\">Magento 2 Facebook Pixel<\/a>&nbsp;and get the extension for your store.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/5-magento-2-facebook-pixel-tracking-extension-700x300-1.png\" alt=\"magento facebook pixel tracking extension\" class=\"wp-image-51614\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once downloaded, extract the zip package file to the root directory of your Magento 2 installation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following commands, one-by-one:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>php bin\/magento setup:upgrade<\/code><\/li>\n\n\n\n<li><code>php bin\/magento setup:static-content:deploy \u2013f<\/code><\/li>\n\n\n\n<li><code>php bin\/magento cache:flush<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The Facebook Pixel Magento 2 extension will be installed on your store.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-2-add-pixel-code\">Step 2: Add Facebook Pixel Code<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In your Magento 2 admin, go to&nbsp;<strong>Stores &gt; Configuration &gt; Meetanshi &gt; Facebook Pixel&nbsp;<\/strong>to configure the extension.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enable the extension and paste the copied code in the&nbsp;<strong>Facebook Pixel JS Code<\/strong>&nbsp;field.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/6-enter-facebook-pixel-code-700x214-1.png\" alt=\"Facebook Pixel JS Code\" class=\"wp-image-51616\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Click the button at the top-right to save the progress.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-3-configure-tracking\">Step 3: Configure Tracking Preferences<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Next, you can also set additional Facebook Pixel tracking preferences for your Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Choose to calculate the conversion value based on&nbsp;<strong>Grand Total<\/strong>&nbsp;or&nbsp;<strong>Sub Total<\/strong>. You can also set custom success page paths (in case you\u2019re not using the default checkout.)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/7-set-tracking-preferences-in-magento-2-700x241-1.png\" alt=\"enter facebook pixel code\" class=\"wp-image-51619\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Optionally, you can also configure to exclude zero-value orders from being tracked as conversions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, click the \u201c<strong>Save<\/strong>\u201d button at the top-right.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it \u2014 with three simple steps, you\u2019ve successfully installed Magento 2 Facebook Pixel code. You can test the implementation of the setup through the&nbsp;<strong>Test Events<\/strong>&nbsp;feature.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><div class=\"meetanshi-cta\">\r\n<div class=\"cta-content-wrapper\">\r\n<span>Magento 2 Facebook Pixel<\/span>\r\n<p>Track your customers action and maximize your Facebook campaign performance.<\/p>\r\n<a href=\"https:\/\/meetanshi.com\/magento-2-facebook-pixel.html\" target=\"_blank\" class=\"btn-primary\">Track Now <\/a>\r\n<\/div>\r\n<div class=\"cta-image-new\">\r\n<img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/11\/facebook-pixel.png\" alt=\"Magento 2 Facebook Pixel\">\r\n<\/div>\r\n<\/div><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"method-2-install-manually\">Method 2: Install Facebook Pixel in Magento 2 Manually<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can directly install the Magento 2 Facebook Pixel code in the head from the admin panel. However, this offers the most basic method of tracking and may not work for all stores.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s the method for Magento 2 add Facebook Pixel code:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In your Magento 2 admin, go to&nbsp;<strong>Content &gt; Design &gt; Configuration<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/8-go-to-content-theme-configuration.png\" alt=\"set tracking preferences in magento\" class=\"wp-image-51624\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now, a list of store themes will be displayed on the screen. Click on the theme you\u2019re currently using to edit it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the configuration screen, scroll down to the&nbsp;<strong>HTML Head&nbsp;<\/strong>section and paste the Facebook Pixel code in the&nbsp;<strong>Scripts and Style Sheets<\/strong>&nbsp;field.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/9-add-facebook-pixel-code-to-magento-2-700x301-1.png\" alt=\"go to content theme configuration\" class=\"wp-image-51625\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Save the configuration and you\u2019re done.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Facebook Pixel code will be added to all the pages on the website.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-debug-pixel-tracking\">How to Debug Facebook Pixel Tracking?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once you\u2019ve set up Facebook Pixel for the Magento 2 store, you can test the implementation in the events manager.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go to&nbsp;<strong>Facebook Events Manager&nbsp;<\/strong>and select the dataset you created earlier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can find the recent events activity on the website from the&nbsp;<strong>Overview<\/strong>&nbsp;tab.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/10-see-events-in-facebook-700x442-1.png\" alt=\"add facebook pi el code to magento\" class=\"wp-image-51627\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You can also move to the&nbsp;<strong>Test events&nbsp;<\/strong>tab and perform events manually on your website to see if they\u2019re being tracked properly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"other-helpful-resources\">Other Helpful Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Try any of the methods provided above to install Facebook Pixel Magento 2 and start optimizing your ad campaigns.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Continue your learning journey with these Magento 2 guides:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/meetanshi.com\/blog\/integrate-facebook-shop-with-magento-2\/\">Integrate Facebook Shop<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/meetanshi.com\/blog\/set-up-magento-2-google-analytics-4\/\">Set up GA4 Tracking<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/meetanshi.com\/blog\/integrate-instagram-feed-with-magento-2\/\">Display Instagram Feed<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>You can make good marketing campaigns better through data-driven decisions. Facebook Pixel in Magento 2 is a tool that can help you collect data and&#8230;<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2518","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=2518"}],"version-history":[{"count":9,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2518\/revisions"}],"predecessor-version":[{"id":18694,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2518\/revisions\/18694"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}