How To Implement Facebook Pixel For Measuring Campaigns

by Nedim Talovic · Updated 13 Jul 2021}}

Among many strong reasons why you should advertise on Facebook, this is the most convincing one.

You can easily target everyone since everybody is on Facebook. You only have to think about your potential and ideal customers. Who are they? Do they:

  • Live in Germany, France, or the UK
  • Have between 28 and 44 years
  • Work in IT industry
  • Use iPhone as their smartphone
  • Frequently travel abroad

Target Customers

You can target all of them without any problems. That’s cool but there’s one advanced feature you should think about - Facebook Pixel.

If you want to make sure your ads work well and your costs go down, you need to measure and test everything. The measuring works thanks to the Facebook Pixel feature.

It’s nothing else than a piece of JavaScript code that gets executed when the appropriate conditions are met.

Here are some basic conditions (site events):

  • Add to Cart
  • Add to Wishlist
  • Purchase
  • Registration
  • Viewed a specific page

In simple terms, you can bring back the visitors who added a product to the cart but didn’t make the purchase.

I bet you know what I’m talking about since you have probably visited some site and later that site has found you on Facebook.

Now, let’s see how to create your first pixel. In the menu, click on Pixels.

Pixels menu

Here, you can see two options:

  • Facebook Pixel
  • Conversion Tracking Pixel (Old)

I’ll of course, go with Facebook Pixel because Conversion Tracking Pixel is deprecated and won’t be available soon. So, click on Set Up Pixel.

Set up your Pixel

There, you have two possibilities:

  • Use an Integration or Tag Manager
  • Copy and Paste the Code

Install your pixel code

I will always recommend you to use the first option because it doesn’t require changing the code of your site or hiring a developer.

The whole idea is that you need to add a Base Pixel, and Event Pixel Code which actually tells to Facebook: Hey, this visitor added a product to the cart - record it.

Now, let’s go back to integration solutions. You got five options:

  • Shopify
  • Google Tag Manager
  • Magento
  • BigCommerce
  • Segment

Choose your solution

As for me, I always use (and recommend) Google Tag Manager, but of course, if you run a Shopify store (e.g.), consider using Shopify integration.

I think Google Tag Manager is the best solution since it’s completely free, reliable (thankfully to powerful Google’s data centers), and it creates custom triggers without the code that lets you track clicks or even count time.

So, if you decide to go with Google Tag Manager, here’s what you need to do. Firstly, click on Google Tag Manager, scroll down a bit, and copy your pixel base code.

Copy and paste Pixel Code

Pixel Base Code should be installed on EVERY page where you want to collect data. Otherwise, your event tracking won’t work.

Now, in a new tab in your web browser, open Google Tag Manager, choose the project, and click on NEW TAG.

New tag

After that, as a Tag type choose Custom HTML and paste the Pixel Base Code.

Tab Configuration

When it comes to triggering, you have to choose All Pages because your base code needs to be everywhere.


Finally, click on Save and publish a new tag.

Publish a workspace change

Now, let’s go back to the Facebook, and move to the second step - Install Event Code - by clicking on Next.

Install event code As you know, I’m talking about events (actions) such as:

  • Search
  • View Content
  • Add to Cart
  • Add to Wishlist
  • Initiate Checkout
  • Add Payment Info
  • Purchase
  • Lead Complete
  • Registration

So, when I place an order on your site, you have to tell to Facebook that happened. The reason why I’m repeating myself is that this is VERY IMPORTANT.

Also, if there’s no desired event within standard actions provided by Facebook, you can always create custom events.

For example, when someone scrolls 30% of the window, you can trigger the custom action and target those people by converting them into an audience. Also, you can trigger an action when someone stays on your time for more than 10 seconds.

Now, let’s imagine that I’m selling a WordPress plugin that costs $49 and I want to return back visitors who didn’t buy anything.

Firstly, I’ll move to the second step - Install Event Code.

Install event code

There are three different tabs:

  • Basic
  • Recommended
  • Advanced

I’ll go with Recommended because since basic type doesn’t allow passing value and currency.

Purchase event code

I’ll only have change the value parameter from 247.35 to 49. I wish to pass additional parameters then I would go with Advanced. 

Purchase event

If these events are not enough for you, you can always implement custom events such as clicking on product descriptions, playing a video, and things like that.

Here’s how Custom Event code looks like.

Custom event

Anyway, I’ll copy Purchase code (Recommended) and open Google Tag Manager again.

The first step is to click on New Tag.

New tag

I’ll name this tag as Facebook Event - Purchase. Again, Custom HTML is a tag type.

Purchase in GTM

In advanced settings, I can schedule date and time where the tag will be scheduled.

This can be useful if you wish to track events in specific time, but for this purpose, it’s useless. Also, there are three tag firing options:

  • Unlimited
  • Once per event
  • Once per page

Here’s explanation from official support page.

Tag firing options I want to be sure that event code gets executed before Facebook Base code.

Also, I don’t want to fire Facebook Event Code when Facebook Base Code fails.

Here’s what I need to select.

Tag Firing Options: Advanced

As for triggering, I’ll select to trigger on Thank You page. If you don’t know how to do that, please read this carefully.

You need to choose Page View as a Trigger Type and set it to fire on Some Page Views. Next, you need to set the URL where the event code occurs.

Here’s the photo.

Thank you

When a visitor places an order, I’ll redirect him to the Thank You page. Finally, click on SAVE and publish the tag live.

The much better option would be to target those who have added the plugin to the cart but haven’t purchased yet. Anyway, let’s see how events are looking in Facebook Pixels.

Facebook pixel events

Here, you can see how many times your events fired. Notice that I currently have three events:

  • PageView
  • ViewContent
  • Purchase

You’re probably wondering what is a PageView since you haven’t seen it in the list of events. Well, PageView is not a standard event - it’s only the result of implementing Base Pixel.

The only thing you can do with PageView is to capture your website traffic into the audience.

On the other hand, ViewContent and Purchase are classic events that you use for conversion tracking and optimization.

On Facebook Pixels page, you can create an audience that you later can use for precise targeting.

Facebook Pixel: Create an audience

For example, you can target:

  • Anyone who visits your site in the last X days
  • People who visit specific web pages
  • People visiting specific web pages but not others
  • People who haven’t visited in a certain amount of time
  • Custom combination

I’ll choose a custom combination since I want to add all visitors into the audience, but without those who visited Thank You page.

Visitors who haven't bought anything

In other words, my audience members will be only those who haven’t bought anything.

Furthermore, if I wish, I could advertise to all customers who spent more than $100 on my site in the last 90 day.

This is very easy since you can filter events by parameters. Of course, except PageView since it’s not a classic event.

Here’s how it looks.

Converting Traffic Into Audience

Surely, as an extra security, I can always make sure that access to my Thank You is allowed only to those who bought something.

Another great example is filtering my visitors in a way that I target only those who spent more than 3 seconds on my site.

Now, I’ll open Audiences and see how many non-buyers we have. Never forget that audiences require having at least 20 people.


Next, you can create a lookalike audience based on your audience. It means that Facebook will use its machine learning algorithms to find similar people to those who have already visited your site.

Facebook knows how old my visitors are, what they like, what they don’t like, in what cities they live and so on.

That way, Facebook is able to find similar people who haven’t visited my site yet or even similar people to my customers. We call this Lookalike Audience.

Here’s how to create it. Select the audience, click on Actions and choose Create Lookalike. Or, click on Create Audience and then, from the menu, click on Create a lookalike audience.

Create lookalike

Next, as a source, you need to set the name of your source - Visitors who haven’t bought anything. It will be added by default.

As a country, I’ll set United States (US), and basically, the lower audience size you choose, the more precise sample you get, and vice versa.

Create a lookalike audience

This is all the result of the data that Facebook collects.

People are worried if they give too much information about themselves, but they need to think about this as a business potential.

Just after I click on Create Audience, my lookalike audience will be there.

Custom and lookalike audience However, it will take some time until your audience gets ready for the usage.

This is how it looks when it gets ready.

Custom and ready lookalike audience

Now, I’ll be able to display ads to people who are similar to my visitors. Facebook knows how old are my visitors, where they come from, what they like, and so on.

That’s the power of Facebook Pixel. Let’s create an ad and return back those who haven’t bought the WordPress plugin.

Firstly, I have to choose a marketing objective. There are a few possible options, but I’ll definitely pick Increase conversions on your website.

Increase conversions on your website

Next, I have to tell to Facebook which conversion event I want to optimize.

Obviously, I’ll choose Purchase because that’s what I’m measuring.

Purchase event in ads

As for the audience, I’ll pick a custom audience I just created.

Please keep in mind that it will take some time that number of audience members increases.

If you implemented base code a few months ago, you’ll be able to target customers from the date of base code implementation.

Choose an audience

You can also filter my audience by location, age, gender, interests, and so on.

Audience: Additional filtering

For example, maybe you know (from Google Analytics) that you have too many visitors from India but they simply don’t like your product.

Or, you know that your best customers come from California. You don’t want to display your ads to the people that aren’t willing to pay your product.

Next, you can show ads only in news feed, ignoring right-column, Instagram, and Audience Network (ads on other mobile apps and websites).


Furthermore, I’ll set my budget and scheduling as usually. I must tell Facebook do I want to optimize ad delivery for:

  • Conversions
  • Impressions
  • Link Clicks
  • Daily Unique Reach

Ad Delivery Methods

The choice of ad delivery will decide when I get charged.

Conversions mean that I’ll be charged per 1,000 impressions. If I want to pay per click, then I have to choose Link Clicks.

Optimize for paying per click

Finally, settings are done, and I can move to creating ads.

Once my ads get approved, I can track and measure my campaigns thankfully to campaigns.

Facebook Ads Results

I hope you liked it.

Finally, I would like to say that you can create custom audience without Facebook Pixel.

Here’s how. Firstly, open Audiences.

Audience menu

Next, click on Create a custom audience.


And then you’ll see four options:

  • Customer File
  • Website Traffic
  • App Activity
  • Engagement on Facebook

Create a custom audiene

Creating an audience from website traffic is actually using Facebook Pixel.

But, creating an audience from Customer File is might be easier since you don’t need to create custom combinations and think about AND & OR logic.

Also, you don’t need to implement Facebook Pixel if you only want to display ads to your customers.

Choose a file or copy and paste data

You simply have to upload your customers and match the data.


Measuring is everything. Period. You are not interested in displaying your ads to irrelevant people. I think Facebook advertising works great content marketing.

Content marketing can dramatically increase the number of visitors your site has, and Facebook marketing can bring back those customers. Being creative is also important.

For example, displaying ads to people who spent more than 60 seconds might be the reason for getting new customers.

Maybe you know that your average customers spend 7 seconds, so when someone stays for a minute or two, then it might be promising.

Again, I think targeting your current customers might be easier with creating a custom audience based on customer data than based on website traffic. However, both ways are great.