Facebook Pixel Implementation Guide

The conversion tracking pixel is no longer available for ad creation. Start using the new Facebook pixel today. Learn how.

In this article, we'll explain how to create a Facebook pixel, add its base code to your website, add its event code to your website and define conversions.

To do:

Creating a Facebook pixel

To create your Facebook pixel:

  1. Go to your Facebook Pixel tab in Ads Manager.
  2. Click Create a Pixel.
  3. Enter a name for your pixel. You can have only one pixel per ad account, so choose a name that represents your business.

    Note: You can change the name of the pixel later from the Facebook Pixel tab.
  4. Check the box to accept the terms.
  5. Click Create Pixel.
Important: If you've created a Custom Audience pixel in the past, you have an older version of the Facebook pixel and won't see an option to create another. However, we strongly recommend that you update to the Facebook pixel base code and add its event codes to access all the products that can help your business.

About the Facebook pixel code

The Facebook pixel code is made up of two main elements:

  • Pixel base code
  • Event code

The pixel base code tracks activity on your website, providing a baseline for measuring specific events. The base code should be installed on every page of your website.

To install the pixel base code:

  1. Go to the Pixels page in Ads Manager
  2. Click Actions > View Code
  3. Copy the base code and paste it between the <head> tags on each web page, or in your website template to install it on your entire website

Events are actions that happen on your website, either as a result of Facebook ads (paid) or organic reach (unpaid). The event code lets you track those actions and leverage them in advertising.

There are two types of events you can send:

  • Standard events. 9 events we're able to track and optimize your ads for without any additional actions. See below for an example of what your website code will look like with standard events installed.

    The Facebook pixel code with a standard event.

    1. Your website's original code: Paste the Facebook pixel code between the <head> and </head> tags of your web page. You may already have other existing code between the head tags, so just place the pixel code underneath that, but above </head>.

    2. Your Facebook pixel base code: Your Facebook pixel code will look like the diagram above, except your pixel ID will be different from 1234567890.

    3. Your standard event code: Within your Facebook pixel code, above the </script> tag, paste the Standard Event code that's relevant to your page (ex: Complete Registration, Add To Cart). You'll need to do this for every page you want to track.

    The key here is that every page of your website should have everything that's enclosed in section 2 (the base code), but different pages will have different snippets of code for section 3 (standard event code). See below for another example.

    What the code looks like on an add-to-cart page.

  • Custom events. Actions that are important to your business, but that you can’t use for tracking and optimization without additional action. Learn how to use custom events.

Adding the Facebook pixel base code to your website's pages

To add the pixel code to your website:

  1. Go to your Facebook Pixel tab in Ads Manager
  2. Click Actions > View Pixel Code
  3. Click the code to highlight it
  4. Right-click and select Copy or use Ctrl+C/Cmd+C
  5. Click Done
  6. Go to your website's HTML and paste the code

Tip: We recommend that you put the code in the header tags of the website HTML to ensure that the it's able to track across your entire site.

Adding the event code to your website's pages

Event code indicates specific actions that are important to your business objective. To add the event code to your website:

  1. Go to your Facebook Pixel tab in Ads Manager.
  2. Click Create Conversion > Track Conversions with Standard Events.
  3. Copy the Event Code of the events that matter to you.
  4. Go to your website's code and place the event code on the relevant pages. We recommend doing this by adding the event code between script tags separately. We recommend not modifying the pixel base code.

Tips: Add a full funnel of events (ex: ViewContent, AddToCart and Purchase) to capture all relevant purchase actions.

On the special pages of your website that you want to track and optimize your ads for, add one of these 9 standard events. For example, someone selling toys on their website would place standard event codes for their add-to-cart page and purchase page. Just copy and paste everything in the standard event code column and add it to the page on your website where you'd like to track this action. Be sure to avoid adding your standard event code to the header section of your website (where you add the Facebook pixel base code). If you do, you won't know on which page of your website a certain event happened. If you'd prefer to use URL rules instead of standard events, you can use custom conversions instead.

Website actionStandard event code
View contentfbq('track', 'ViewContent');
Searchfbq('track', 'Search');
Add to cartfbq('track', 'AddToCart');
Add to wishlistfbq('track', 'AddToWishlist');
Initiate checkoutfbq('track', 'InitiateCheckout');
Add payment infofbq('track', 'AddPaymentInfo');
Make purchasefbq('track', 'Purchase', {value: 0.00, currency: 'USD'});
Leadfbq('track', 'Lead');
Complete registrationfbq('track', 'CompleteRegistration');

Note: You can also add different parameters for each standard event code, such as Content ID, value and currency. The conversion standard event requires value and currency parameters to work. Parameters are optional for all other standard events. Learn more about parameters.

Other options

I want to install just the image tag of the Facebook pixel

In some cases it may be necessary to use only the image tag of the Facebook pixel, such as when you're piggybacking off existing container tags (ex: DFA, Atlas). If so, you should use the PageView image tag on every page of your site, then create another image tag for the standard events on specific pages.

1: The Facebook pixel code: We recommend using this entire code.

2: The image tag: Please make sure you don't copy the <noscript> tag as well.

Below is an example of how you'd set up Facebook pixel image tags across key pages of your website with just the image tag. Keep in mind you have to replace 1234567890 with your Facebook pixel ID, and adjust your parameters (ex: currency) depending on your website.

On a product page, you would have these two tags:

<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1234567890&ev=PageView"/>

<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1234567890&ev=ViewContent"/>

On your add-to-cart page, you would have these two tags (plus parameters for the AddToCart event):

<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1234567890&ev=PageView"/>

<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1234567890&ev=AddToCart&cd[currency]=USD&cd[value]=0.00"/>

On your purchase page, you would have these two tags (plus parameters for the purchase event):

<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1234567890&ev=PageView"/>

<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1234567890&ev=Purchase&cd[currency]=USD&cd[value]=0.00"/>

I can't place standard events between the </head> tags

While we recommend placing the base code and standard events between the </head> tags on pages of your website, both will still work outside (ex: between the </body> tags). Keep in mind the base code must fire before the standard event.

Confirm your pixel is implemented correctly

The Facebook Pixel Helper is a tool that helps you check whether your Facebook pixel is working properly. Learn more.

After you've installed the Facebook pixel on your website, go to a web page the pixel was placed on. If it's working, the pixel will send information back to Facebook and you'll be able to see activity in the Facebook Pixel page in your Ads Manager. Your pixel's status will also be set to Active.

The main graph on the Facebook pixel page shows total pixel traffic over time (the default view for all data on the dashboard is the past 7 days, but you can adjust it using the dropdown on the top right).

At a glance, you can tell whether the data is roughly where you would expect it to be. Does it generally match your website analytics reporting? To check, compare the Total Traffic number in the upper right-hand side with the total number of website visits in the past 7 days (as reported in your website analytics).

Keep in mind data on this page refers to the total number of pixel fires, regardless of whether they were associated with an ad. This means the total number should roughly align with your overall website/page visit volume, not just attributed traffic from Facebook. It's normal that Facebook's numbers may be different from a third party’s, but if there's a very large discrepancy (or you don’t see any pixel traffic), something may be wrong.

Check this graph to see your total pixel fires.

After you've checked your total pixel fires, you should ensure your events are being reported correctly. If you have events on any of your web pages, you should see them in your Events tab below your traffic graph. Both Standard and Custom Events will show up on this tab. If you have the wrong Event enabled, or it’s set up on the wrong page, this will help you find it.

Events are case sensitive, so if you accidentally added fbq('track', 'viewcontent'); to one of your web pages instead of the correct standard event code fbq('track', 'ViewContent'); you'll see an event called viewcontent show up in the events tab instead (which will render as a custom event rather than a standard event), so you'll want to edit your pixel code on that page again to replace that code with the correct standard event code. Please note that PageView is the default event that the pixel fires on every page of your website (it's not a standard event).

Learn more about the other tabs available in this table.

Use the Events tab to troubleshoot your events.

Troubleshooting Pixel and Event Implementation

We recommend downloading the Facebook Pixel Helper to troubleshoot implementation problems. Keep in mind you have to be using the Chrome browser for it to work. Once the Pixel Helper is installed, a small icon will appear next to your address bar. Navigate to your website in your Chrome browser and click the Pixel Helper icon.

The pop-up will tell what pixels/events were found on the page, and whether they have loaded successfully. If you added standard events to your pixel code on certain pages, you'll need to complete a test conversion for each (ex. add an item to your cart to test an “AddToCart” event) in order to confirm that each event loads on the desired page or action. If your pixel's PageView event loads on every web page, and each of your standard events load successfully (on the desired pages only), you're ready to attach the Facebook pixel to your ads.

If the Pixel Helper tool displays errors or warnings on any of your pages, click Learn More to help resolve the issue. For a full list of possible Pixel Helper tool errors, warnings and recommendations, see our developers site.

In order to resolve most Pixel Helper errors you'll need to check the HTML code on the web page where you received the error. To check the HTML code, go to the desired web page and right-click on the screen, then select “Inspect” and search for your pixel ID (you can usually use “Control + F” or “Command + F” to bring up your browser's search bar).

  • If you don't find the pixel ID anywhere in the code, it may have not been placed on that page. If you installed the pixel using a tag manager then you won't see the code on the actual web page, so you'll have to troubleshoot within your tag manager.
  • If you do find the pixel ID, check the code carefully against your code in your pixel dashboard (under Actions > View Pixel Code) to make sure everything between the <script> and </script> tags is exactly the same and that the pixel wasn't placed in the middle of another code block on your web page. You should find 2 instances of your pixel ID on each page where you placed the pixel (one in the <script> portion of the code and one in the <no script> portion. If you find more than 2, it's likely that the code has been placed multiple times, so you can delete any additional instances.
  • When troubleshooting standard event implementation, make sure the the event code (ex. fbq('track', 'Purchase', {value: '0.00', currency:'USD'}); for a Purchase event) is placed either:
    1. Directly between the “;” after the PageView event and the </script> tag, or;
    2. Directly below the entire base code (in which case you'll need to add <script> directly before the event code and </script> directly after the event code).

Troubleshooting Custom Conversions

One of the most common issues with custom conversion rules is when using the URL Equals option, as it will not count a conversion if someone lands on a version of the URL with any additional text beyond what is pasted into the URL field here (ex: UTM parameters, http vs. https, or even an extra “/” at the end).

To maximize your ability to track your custom conversion accurately, we suggest using URL Contains and pasting the minimum portion of the URL needed to distinguish this page from any other pages on your website (ex: Starting after “www” and ending before “.com”, “.org”).

Troubleshooting Ad Performance

One important thing to note in order track ad performance properly when using the Facebook pixel is that you'll need to customize your ads reporting columns in Ads Manager in order to show the most important data. By default, the Results column for a Website Conversions campaign will display the total number of events/conversions associated with your ads. That means if you have ViewContent, AddToCart and Purchase events on your website, the Results column will display the aggregate number of all these events, and the Cost column will display the cost per the total number of these events as well. If you really only care about the number of Purchases and cost per Purchase, you'll need to customize your columns to select “Purchase (Facebook Pixel)” and “Cost per Purchase (Facebook Pixel)."

If you've just transitioned from the old conversion pixel and are optimizing for conversions, you may experience a few days of decreased performance while the new pixel gathers the data needed to optimize sufficiently. Please review the Optimization section in the Conversion pixel transitioning guide for recommendations and best practices.

If you're optimizing for conversions and find that you're unable to spend your daily budget (due to under-delivery) and are seeing a high cost per conversion, there's a good chance your ads are not getting enough conversions to provide sufficient data to our delivery system in order to optimize (which needs about 25 conversions to start optimizing properly). If you set a target bid, you may also see delivery decrease if our system is unable to get conversions at the desired target bid. This is often due to having small or overlapping audiences, low bid to budget ratio, poor creative/targeting or high negative feedback. Learn more about conversion optimization.

Was this information helpful?

Defining conversions

In order to track and optimize for events on your website that matter to you, you need to define them as conversions. Standard events are already conversions, so if you're using standard events, there are no extra steps needed. They'll be available for you to track or optimize on.

If you're using custom events, plan to use URL-based rules, or want to define a conversion as a specific subset of standard events, you'll need to take the steps detailed below.

Using custom events as conversions

To use custom events as conversions:

  1. Implement custom events in your page code
  2. Go to your Facebook Pixel tab in Ads Manager
  3. Click Create Conversion > Track Custom Conversions
  4. In the "Rule" section, click the dropdown and change URL Contains to Events

    Note: It may take a moment for Events to appear

  5. In the field underneath the dropdown, select the custom event you want to define as a conversion
  6. In the "Category" section, click the Choose a Category dropdown and select the most appropriate choice
  7. Name the custom conversion
You can also add a default conversion value, which we'll use if values aren't being sent dynamically as a parameter within the custom event. When a value isn't set or sent, we'll set it to 0 by default.

View your custom conversions.

Using a subset of standard events as conversions

To use a subset of standard events as conversions:

  1. Go to your Facebook Pixel tab in Ads Manager.
  2. Click Create Conversion > Track Custom Conversions
  3. In the "Rule" section, click the dropdown and change URL Contains to Events.

    Note: It may take a moment for Events to appear.

  4. In the field underneath the dropdown, select the standard event.
  5. If the event has sent parameters with it, you'll be able to select the key pair value. If you do not see it but expect it, make sure the event is set up to send data in parameters.
  6. In the "Category" section click the Choose a Category dropdown and select the most appropriate choice
  7. Name the custom conversion.
You may also add a default conversion value. We'll value the given conversion at the amount you specify if values aren't being sent dynamically as a parameter within the custom event. When a value isn't set or sent, we'll set it to 0 by default.

View your custom conversions.

Running your campaign

To create a campaign using your pixel:

  1. Go to ad creation
  2. Select the Increase conversions on your website objective
  3. Click Continue
  4. Choose a conversion event
  5. Finish creating your campaign, making sure you:
    • Select Conversions as your "Optimization for Ad Delivery" choice at the ad set level
    • Enter the URL of the page you want to track conversions on in the "Destination URL" field at the ad level
  6. Click Place Order when you're done

Keep in mind you can use the Facebook pixel in the same way when creating your ads in Power Editor. Your ad will automatically track all available conversion events so you don't need to manually select a pixel for tracking. You'll be able to see all this data in your ads reports.

Read our frequently-asked questions or learn more about the Facebook pixel in our developers site.
If you're looking to transition to the Facebook pixel from an older version of the pixel, check out our guides for transitioning from a conversion tracking pixel and upgrading from a Custom Audience pixel. Learn more about what's happening to the conversion tracking pixel here.

Was this information helpful?