How to Install the Facebook Pixel

How to Install the Facebook Pixel in 2021

12 min read

The Facebook Pixel is an incredibly powerful tool in any marketer’s toolset.

With it, you’re allowed to measure the effectiveness of your advertising campaigns, track user behavior across your entire website, and even build highly specific audiences to feed your remarketing campaigns.


Whether you’re a beginner or an advanced Facebook Marketer, the Facebook Pixel will surely become one of your biggest allies and help you get the most out of your Facebook Ads budget.

Let’s dive in.

What is The Facebook Pixel?

The Facebook Pixel is a short snippet of JavaScript code that you place on your website. Essentially, this code works by dropping a cookie on your page visitor’s browser, which can then be used to serve multiple purposes.

  1. Build Custom Audiences: once users have been tagged by your pixel, you can add them to custom audiences and target them via remarketing campaigns.
  2. Track user behavior: through standard events, you’re able to understand which products users are viewing, where they are clicking, and more.
  3. Optimize campaigns: with the collected data, Facebook can help you show ads to the most relevant users in your audience pool.
  4. Dynamic Ads: do you own an e-commerce store? The Facebook Pixel can help you create individual ads based on the products your users have seen.
  5. Measure advertising effectiveness: most importantly, you’re able to manually assess the data and see which campaigns, ad sets, and ads, have been providing the best results.

Getting Started

Before anything else, you need to generate your Facebook Pixel – if you already haven’t done so.

 To do so, you will be required to own a Facebook Ads account from where you can generate the code. If you don’t already own an Ads Account, you create one by heading over to the Facebook Business Manager and following along the steps.

Afterward, to access the code, navigate to your Ads Manager, and, under the ‘Manage Business’ column, click ‘Events Manager’.

Once you’ve accessed this panel, click on the grey button ‘Add Events’, and then ‘From a New Website’.

Or ‘From the Pixel’ if you want to use the Event Setup Tool.

Then, click on ‘Install code manually’…

… and click on ‘Copy code’.

You now have copied the base code for the Facebook Pixel.

Before we proceed, go ahead and paste that code into a Word document. Hold on to it for a minute.

How The Facebook Pixel Works

As mentioned earlier, the Facebook Pixel is a piece of JavaScript code that you add to each page on your website.

For it to work, you need to add it into the header section of your website.

Essentially, whenever a user visits one of your pages where your Pixel is installed, an event is triggered within the code – or fired, as it is commonly referred to – that lets Facebook know what happened.

For example, if you look at the image in the code above, there is a line of code that looks like this:

fbq(‘track, ‘PageView’),

In this line, Facebook is tracking a ‘PageView’ event which lets Facebook know someone has visited this page. This is the standard event that you will be including into every single page on your website.

Besides this event, there are as much as 17 additional standard events that you can use to track specific user actions. Take a look at how to track user actions using standard events.

  1. AddPaymentInfo
  2. AddToCart
  3. AddToWishList
  4. CompleteRegistration
  5. Purchase
  6. Lead
  7. Search
  8. And more!

You can access all the events in Facebook’s developer documentation here.

Don’t worry if this all seems too technical, you don’t require any coding knowledge to fully leverage the Facebook Pixel.

For now, let’s keep things simple and focus on how to install the PageView event.

Installing the Facebook Pixel

To install the Facebook Pixel, you are required to copy and paste the code into the header section of every page on your website. There are multiple ways to do so, depending on how you have set up your website.

I will cover three different options in this post, so feel free to skip any that don’t matter to you.

  1. Google Tag Manager
  2. WordPress
  3. Shopify


Google Tag Manager

The first (and recommended) method is to install the Facebook Pixel via Google Tag Manager. After installing Google Tag Manager on your website, click on ‘New’, under the ‘Tags’ menu in the left bar.

At the time of this writing, Google Tag Manager does not include the Facebook Pixel as one of its featured tags, so we’ll need to add the Facebook Pixel via Custom HTML. After naming your tag, click on custom HTML and paste your code into the box.

After pasting your code, the last step is to define a trigger for when you want to event to fire. In this scenario, we want our ‘PageView’ event to fire whenever any page on your website loads.

This means that whenever a user visits one of your pages where the Pixel is installed, once the page is finished loading, the Pixel will fire and indicate a PageView event was triggered.

Installing on WordPress

If you don’t have Google Tag Manager installed, and you’re hosting your website on WordPress, there’s an even easier solution to install the Facebook Pixel.

Introducing: Pixel Caffeine.

With this simple plugin, you only need to either connect your Pixel via your Facebook Account or manually insert your Pixel ID (that can be found under your events manager) into the text box.

You can find your pixel ID in your Pixel code, right above your ‘pageview’ event, under ‘fbq(‘init’, ‘XXXXXXXX’);’.

Installing on Shopify

Late into 2020, Shopify updated its installation method for the Facebook Pixel. These changes were done to account for Facebook’s Conversions API (CAPI) launch.

To integrate the Pixel with your Shopify store, you’ll have to follow a few simple steps.

Open your Shopify Admin section, click on Online Store, and then Preferences. Right under Google Analytics, you will see the Facebook Pixel section.

Click on “Set up Facebook”.

You will then have to create a Sales Channel. To do so, review what Facebook will be able to access and hit the “Add sales channel” button.

Finally, connect all your Facebook assets to Shopify – Business Manager, Ad Account, Pages, etc. – and click on “Finish Setup”.

Before you finish, under the “Data Sharing” option, make sure you enable the “Maximum” customer data sharing level. This will enable Facebook’s Conversion API which will allow for much better attribution.

Tracking Conversions: Standard Events

So far, we’ve learned how to have the Facebook Pixel fire whenever a user visits one of our pages.

But how do we use the Facebook Pixel to measure specific conversions, such as product purchases, leads, or other user specific goals?

If you’ve been following along, you’ve understood that for an event to be fired, it needs to be triggered by an action.

For example, the pageview event is triggered when a page loads.

As such, if you wanted to track a product purchase, all you would have to do is add the ‘purchase’ event – from the standard events made available by Facebook – to your purchase confirmation page.

fbq('track', 'Purchase', { });

Or, in other words, your thank you page.

Once a user has reached your thank you page, the purchase event will fire, and let Facebook know someone has purchased a product – allowing you to trace this conversion back to the advertisement that generated it.

If you’re using Google Tag Manager, this can be easily done by changing the trigger to fire only on specific URLs.

Here’s what this looks like.

Furthermore, you can also track Facebook standard events on button clicks, when a user plays a video, or scrolls down a certain length of the page.

However, I will discuss this on another post, as the goal of this post is merely to install the Pixel.

Checking if Your Pixel is Installed Correctly

Regardless of how you installed your Pixel, you will always need to validate whether it has been correctly installed, or not.

The easiest solution to do so is to use the Facebook Pixel Helper Chrome extension.

Simply install the extension and open your website. On the top right, you should see the extension icon and, once you click on it, the Facebook Pixels found in that specific page.

Uma imagem com captura de ecrã

Descrição gerada com confiança muito alta

If your Pixel has been correctly installed, you should now see the green icon next to your pageview event.

Note that if you have any other events installed, such as a purchase event, it will also be displayed.

Closing Thoughts

The Facebook Pixel is an incredibly valuable tool and, while its advantages are obvious, a lot of marketers aren’t benefitting from it to its fullest.

I believe the main reason for this is due to less technical users feeling intimidated by its installation when, in fact, anyone can do it.

It is, without a doubt, the most important element into cutting on unwanted spending in Facebook Ads, and improving/scaling up campaigns up to a profitable point.

If you’re not using it yet, and feel it is too complicated to install, or that it isn’t worth the ‘hassle’, please consider re-reading this post and installing the Facebook Pixel on your website asap.

It will be worth your time, trust me!

Up To You

Did you have any trouble setting up the Facebook Pixel?

Let me know in the comment box below and let’s talk!

Show CommentsClose Comments


  • P
    Posted November 26, 2020 at 3:13 pm 0Likes

    Hey, the Shopify route is different now, as you need to install an App instead of just adding the code in settings.

    • Alex
      Posted November 26, 2020 at 6:09 pm 0Likes


      Thanks for the heads up – we’ve updated the post with the latest method.


Leave a comment