How to set up the Facebook pixel through GTM

The Facebook pixel is a piece of code placed on your website to track site visitors.

Jakub Gombár

Jakub Gombár

AI Team Leader & Co-Founder

22. September 2020

3 min

Advanced

The Facebook pixel is a piece of code placed on your website to track site visitors. The pixel lets you target campaigns at people who visited your site (Facebook remarketing/retargeting), or target people who visited only a particular page, and so on.

Every ad account should have one pixel. The code consists of two main parts: the base pixel code and the event code. The base pixel code tracks all traffic to your pages. Event codes are further pieces of code you can add beneath the default pixel code on particular pages of your site, letting you track certain actions on those pages, such as registrations or completed purchases.

Sample base Facebook Pixel code with script and noscript parts

How to create a pixel

If you do not yet have an FB pixel, creating one in your Business Manager is very simple (a guide to creating a BM is HERE).

1. In the left-hand menu click Business settings.

Facebook Business Manager – Business settings item in the left menu

 

2. Then choose Data sources, then Pixels in the left-hand menu, and click the Add icon.

Business Settings – Data sources, Pixels and the Add button to create a pixel

 

3. In the window that appears, fill in the pixel name and the web address you are creating the pixel for, and click Next. To find your bearings more easily where there are several pixels, I recommend naming it after the site the pixel will sit on.

Facebook – naming the pixel and entering the website URL when creating it

 

4. The next window shows 2 options; we choose the first one to carry on with the setup.

Facebook – choosing to continue managing the business or set up the pixel now

 

How to insert the pixel through Google Tag Manager

1. First open your GTM account. In the left-hand menu click Tags and then New on the right.

Google Tag Manager – Tags section and the New button to create a tag

 

2. A new window opens; click Tag Configuration.

Google Tag Manager – new tag with an arrow pointing to Tag Configuration

 

3. Then click the gallery, where we will look for a suitable template for our FB pixel. Templates can be built or chosen from predefined ones. This set of features helps make creating tags simple and clearer still. You can read more about templates HERE.

Google Tag Manager – choosing a tag type and the Community Template Gallery link

 

4. In the top right corner click the magnifying glass and search for "facebook". Then click the "Facebook Pixel" template. We use Simo Ahava's templates, which have always served us well ;)

GTM Community Template Gallery – Facebook Pixel template by Simo Ahava

 

5. The template's detail appears; at the top right click Add to workspace.

Facebook Pixel template details in GTM with the Add to workspace button

 

6. The Tag Configuration window appears again, where you fill in the Facebook Pixel ID. You will find that ID in BM – Business settings -> Data sources -> Pixels.

Google Tag Manager – entering the Facebook Pixel ID in the tag configuration

 

7. Once the FB Pixel ID is filled in, click Triggering below the Tag Configuration box.

Google Tag Manager – configured FB Pixel tag with an arrow pointing to Triggering

 

8. Choose the "All pages" trigger, name the tag and save it.

Google Tag Manager – choosing the All Pages trigger for the Facebook Pixel tag
Google Tag Manager – named FB Pixel tag with the All Pages trigger before saving

 

Tip: If you do not want to hunt for and copy the ID every time (whether the FB pixel or another), create a variable that updates automatically in every tag it is used in whenever it changes.

1. In the left-hand menu click Variables and then New.

Google Tag Manager – Variables section and the New button for a user-defined variable

 

2. A window appears; click Variable Configuration and choose the variable type "Constant".

Google Tag Manager – choosing the Constant variable type

 

3. Enter the FB Pixel ID as the value, name the variable and save.

Google Tag Manager – FB Pixel ID variable with the pixel ID value before saving

 

4. From then on you need not copy the ID into your tags every time; you can select it by clicking the plus.

Google Tag Manager – icon for inserting a variable into the Facebook Pixel ID field

 

5. Ta-daa! Just save it and you are done :)

Google Tag Manager – FB Pixel tag using the FB Pixel ID variable instead of a manual ID

 

The last and very important thing you still have to do is publish everything. At the top right click "Submit", then "Publish" and then "Continue" or "Skip".

Google Tag Manager – tag list with FB Pixel and an arrow pointing to Submit Google Tag Manager – submitting changes and publishing a version with Publish Google Tag Manager – container version description with Skip and Continue buttons

 

As we mentioned at the start, the Facebook pixel gives us important information we can use to build better Facebook ads and target them better too. With the pixel set up we can measure site traffic, build remarketing audiences and so on. It helps us improve the conversion rate of Facebook ads and achieve a better return on investment.

Recommended reading

The latest trends, proven practices and analyses from the digital world. Find out how to take your technology and marketing growth further.