
Getting your Facebook Ads to work is not a piece of the pie. Without accurate insights into customers' behaviour, setting up effective Facebook campaigns is going to be challenging.
That's why you need Facebook pixel — a small piece of code that makes a huge difference. You add Facebook pixel to Magento 2, allow it to track information about different events customers perform on your website and send it to Facebook Ads Manager.
In this guide, we'll walk you through each step you need to take to make Facebook pixel work. You'll learn how you can set up Facebook pixel in Magento 2 with no technical skills, using only .
Prerequisites for Facebook Pixel in Magento
Before you add Facebook Pixel to Magento, make sure you:
- Create Facebook Business page (mandatory) — needed to represent your business in ads.
- Create Facebook Ads account (mandatory) — needed for managing and tracking your ads.
- Create a Business Manager account (recommended) — needed for managing ad accounts, pages and payments.
- Have access to the Magento theme settings — to paste the Facebook Pixel script.
- Install the Magefan Facebook Pixel Extension (recommended) — for smoother and more accurate integration.
Once all that's in place, you can move on.
How to Add Facebook Pixel Code to Magento?
Adding the Facebook Pixel script to Magento requires you to retrieve the tracking script from Facebook and paste it into the Magento admin.
Important: before you get the Facebook pixel script, note that the script only tracks the PageView event. You need to implement all the other events manually through that script. So, it's recommended to use the Facebook Pixel Extension for Magento, which we describe in the next chapter.
Navigate to Facebook Events Manager > Datasets and choose a specific source. Then click on Manage Integration under Integrations.
![]()
Once there, choose Install pixel on new website from the Manage dropdown.
![]()
You're redirected to the setup page where you can Copy the Facebook pixel script.
![]()
After you have the script, go to your admin panel and paste it under Content > Design > Configuration > specific theme settings > Head > Scripts and Style Sheets.
![]()
That's how you add Facebook Pixel code to Magento. But again, it won't track any events, except page views. So, keep reading to learn how to implement Facebook pixel with all the vital eCommerce events.
How to Add Facebook Pixel to Magento with Events?
The easiest way to add Facebook Pixel to Magento with all the conversion events is to use the Magefan Facebook Pixel Extension. It automatically creates eCommerce events, so you don't have to rely on the code or set up each even manually.
Step 1: Create Facebook Pixel
If you haven't done this already, go to Facebook Events Manager to create Facebook pixel. Then find and click on the +Connect Data in the left menu, choose Web and click Next.
![]()
Then Name your Pixel and press Create.
Note: it is recommended to choose a name that represents your business name rather than a specific campaign.
![]()
Next, choose the Set up manually option from the Recommended setup options.
![]()
Important: if you haven't specified an email for your business account for some reason, you won't be able to choose this option. So just go to your Business Account settings and confirm your email.
Finally, choose how to connect to your website. Select Meta Pixel only and click Next. If you like, you can set up Conversions API for Magento later.
![]()
Step 2: Get your Facebook Pixel ID
Right after you create your Facebook Pixel, you'll be redirected to the dataset Settings. Find the Pixel ID under the pixel name or the Dataset ID field.
![]()
If you already have a Facebook Pixel creator, navigate to Datasets in your ads account, choose the dataset you need and find the IDs in the Settings tab.
Step 3: Paste Facebook Pixel ID into Magento admin
Once you get your Facebook Pixel ID, go to Magento admin panel > Stores > Configuration > Magefan Extensions > Facebook Pixel and paste it into the corresponding field. Don't forget to Save the settings.
![]()
Step 4: Verify Facebook Pixel connection
To verify whether the Facebook Pixel is connected to your Magento store, you need the Meta Pixel Helper extension for Chrome.
![]()
Add the extension and go to the website you have installed the Facebook Pixel on. An extension popup will show how many pixels it finds on the page and whether they work properly.
![]()
Step 5: Test Facebook Pixel events
Once you verify the connection, you can test the Facebook Pixel events directly in your Ad Manager account. Just go to the dataset you've set up and switch to the Test events tab.
Choose to test the website's events and paste your website URL.
![]()
After you press Test events, your website opens in a new tab. Navigate through it and perform some actions to see them displayed in the Facebook event testing tool.
![]()
Note: it might take some time for Facebook to display the events. Wait a little, reload the page or reenter the dataset to see the events displayed in this tab.
Step 6: Check Facebook Pixel Analytics
Before you check how your Facebook Pixel is performing, give it a few days. After some time, you can go to your pixel in Data Sources and check the overview of all activity and events for a certain period.
![]()
Can You Use Facebook Pixel for Different Store Views?
Facebook Pixel Extension by Magefan enables you to track events per store view with different Facebook Pixel IDs. So, if you want to create personalised ads based on customers' location or languages, just create different datasets and connect them to Magento.
Then you'll be able to create a custom audience for each event and set up personalised Facebook ads based on the gathered data.
However, that's now it.
You need to make data-driven decisions not only when it comes to Facebook ads. If you want to enable Google dynamic remarketing in Magento, you also need to set up .