The Ultimate Guide to Facebook Pixel integration

On the surface, implementing Facebook Pixel seems a difficult task. However it opens new opportunities for productive work in Facebook Ads.

In this guide below we addressed in detail the questions you may face while setting Facebook Pixel.

Unfortunately, the navigation through the article could not be displayed. Check if JavaScript is enabled in your browser
Navigation
Unfortunately, the navigation through the article could not be displayed. Check if JavaScript is enabled in your browser

What’s Facebook Pixel and why would you need it?

Facebook Pixel is a fragment of JavaScript code that gets added to the website pages. The tracker helps evaluate ads performance and explore user actions (events). When the user performs a certain action, for instance, adds a product to the cart or places an order, Pixel sends the info to Facebook Ads. 

Why is this needed?

Set conversion tracking

By adding Pixel to the website and setting event tracking in Ads Manager, you’ll learn which targeted actions are performed by the users who came to your website via Instagram or Facebook ads.  

Facebook Ads allows you  to create 17 standard events (there used to be 9 before): purchase, lead, content view, product subscription, etc. We’ll cover the full list of the events and tracking options below. Besides, you’ll be able to create custom events which we’ll touch upon further on as well.  

Starting from spring 2021 Facebook Ads allows tracking up to 8 events for each domain name. If your ads account has more events you’ll have to prioritize them in Events Manager.

Eventually you’ll be able to track conversions from advertising campaigns and check Acquisition Cost (cost of acquiring a client). All the data including registrations, clicks, and purchases will be presented in Facebook Ads reports. 

Set remarketing lists

Remarketing lists help target at people who previously visited your site or performed certain actions: 

Example: 

  • added items to cart but didn’t place order;
  • visited the site within the past 30, 60, 90 … 180 days;
  • are top active users or spend on the site most of the time;
  • viewed certain pages, for instance, the catalog or certain items.

You can set characteristics of users truly interested in your goods or services. Targets can be combined. You can use previously collected remarketing lists for creating “Similar audiences”.

Facebook algorithm will be looking for users that are at most similar with who you indicated via your remarketing lists. The system will consider gender, age, interests, location, marital status and other characteristics of the same audience.

Optimize advertising campaigns

You can use standard or user conversions to set  “Optimization for conversions” option. Facebook will optimize advertising campaigns to reach the maximum number of conversions due to the set parameter: order, call to a manager, website visit.

Facebook will track user actions on the website and automatically display ads to people with a higher chance of conversion. With “Optimization for conversions” you’ll decrease the cost of requests and purchases while growing their number.

How to create Facebook Pixel?

There are two options: via Business Manager or via Ads Manager. Business Manager is optimal for setting Pixel. Besides, Business Manager reveals more opportunities: it allows to share Pixel with other users or manage access to Ads Manager or a page.

Creating Facebook Pixel via Business Manager

Before creating Pixel start an account in Business Manager. If you already have one, make sure it’s still available. Check if you’re managing the account you plan to use. 

How to set:

  1. Enter the company settings in Business Manager.
  2. Choose the proper account.
  3. Go to the tab “Events Manager”— it’s available in the quick links.
  4. To the left you’ll find a button «Connect Data Source». 
  5. Choose the data source “Web”.
  6. Press “Get Started”.
  7. Choose the manual setting of Pixel code. .
  8. Facebook will generate a JavaScript code. Copy it by pressing the button “Copy Code”.

Now we can move on to Google Tag Manager to set the tag.

Setting Pixel via Google Tag Manager

Now let’s check how to withdraw Pixel via GTM:

To that end:

  1. Create a new tag. Indicate its name, for instance, Facebook Pixel. 
  2. Specify the tag type: Custom HTML.
  3. Insert the code copied from Ads Manager. 
  4. Standard code gets placed on all the pages and tracks Page View. In the trigger settings indicate All Pages.
  5. Save settings.

Note: the event “Page View” is included in Facebook Pixel base code. It  tracks users who visit the page with a base Pixel code installed, in our case for all the users of the website.  

Done! You installed Facebook Pixel to your website. 

Tracking Standard Events

Standard events are actions available in Facebook Ads by default for tracking events on the website. By adding a code for the event to the site you’ll be able to register conversions, optimize ads, and create audiences. 

Like we stated before Facebook allows to track 17 standard events, which becomes possible by calling the function fbq(‘track’, ‘…’); with the indicated name of the event.

Below you can see all the standard events identified by Facebook. Press on each standard action in the sheet and the generator will offer you a code for the selected action. 

Action on site Description JS-code
Add to cart The user adds item(s) to the cart — for instance, presses the button “Add to cart”. fbq(‘track’, ‘AddToCart’);
Add to wishlist 

The user adds item(s) to the wishlist — for instance, presses the button “Add to wishlist”.

fbq(‘track’, ‘AddToWishlist’);

Add payment information

The user gets to the payment page — for instance, presses the relevant button.

fbq(‘track’, ‘AddPaymentInfo’);

Complete registration

The user provides information in exchange for the service your company offers — for instance, registers on the website or subscribes for a mailing list.

fbq(‘track’, ‘CompleteRegistration’);

Contact

Any contact between the user and the company: a call, email, SMS, chat message, etc.

fbq(‘track’, ‘Contact’);

Donate

The user donates money in favor of the company or some initiative.

fbq(‘track’, ‘Donate’);

Customize product

The user customizes product(s) with the setting instrument or other application of the company.

fbq(‘track’, ‘CustomizeProduct’);

Initiate checkout

The user initiates checkout — for instance, presses the button “Checkout”.

fbq(‘track’, ‘InitiateCheckout’);

Purchase

The user completes purchase which is indicated by receiving the order, purchase confirmation, or sending a check for successful transaction — for instance, redirecting to a page with order confirmation or a page with a thank you message.

fbq(‘track’, ‘Purchase’, {value: 0.00, currency: ‘USD’});

Find location

The user looks for one of the company’s points to visit — for instance, when the user looks for a certain product and finds it in one of the company’s stores.

fbq(‘track’, ‘FindLocation’);

Lead

The user provides information with understanding that the company may contact them later — for instance, signs up for a trial or sends a filled application.

fbq(‘track’, ‘Lead’);

Schedule

The user signs up for a meeting in one of the company’s points.

fbq(‘track’, ‘Schedule’);

Start trial

The client starts using a trial period of working with the product — for instance, signs up for an appropriate subscription.

fbq(‘track’, ‘StartTrial’, {value: ‘0.00’, currency: ‘USD’, predicted_ltv: ‘0.00’});

Search request

The user types a request on the website, app or other monetization object that belongs to the company — for instance, looking for a product or service.

fbq(‘track’, ‘Search’);

Subscribe

The user signs up for a paid subscription for a product or service offered by the company.

fbq(‘track’, ‘Subscribe’, {value: ‘0.00’, currency: ‘USD’, predicted_ltv: ‘0.00’});

Submit application

The user submits an application for a program, product, or service offered by the company — for instance, for a job position, educational course, or a product currently unavailable on the website.

fbq(‘track’, ‘SubmitApplication’);

View Content

The user visits the page that the company is interested in — for instance, a targeted page or a product page. However you won’t know which information the user went through or what he did on the page.

fbq(‘track’, ‘ViewContent’);

The example below shows tracking the event “Add to cart”:  

<script>
fbq('track', 'AddToCart');
</script>

To set tracking on the Google Tag Manager side you need to: 

To do this:

  1. Create a new tag of HTML level
  2. Add a necessary method of the event tracking. In our case adding a product to the cart. 
  3. Pay attention to the tag settings. .
    It’s important that the event code turns on after Facebook Pixel base code.
  4. As an activation trigger indicate the trigger responsible for tracking a necessary action. 

Let’s look at another example. 
Tracking the event «Purchase»:

<script>
fbq('track', 'Purchase', {
value: 0.00, 
currency: 'USD'
});
</script> 

You may notice that beside the event ‘Purchase’ we send additional data: value and currency, where

  • value is the revenue from the transaction
  • currency is the currency of the transaction

In the next block you’ll find an example of how to insert value and currency from the data of ecommerce Google Analytics to Facebook Pixel code. 

Standard events for ecommerce projects based on Google Analytics Enhanced Ecommerce

There are types of events in Google Analytics called Enhanced Ecommerce. The instrument allows to collect such data as: id-transactions, sum of transaction, data on passing the funnel as well as efficiency of products, listings, and promotions. 

We  described in detail how to implement Enhanced Ecommerce in this guide. Instead of focusing on the technical implementation let’s check how to get Enhanced Ecommerce data and transfer it to Facebook Pixel.

You can take data from Enhanced Ecommerce and insert it as variables into Facebook Pixel. Let’s cover the process with “Purchase” example. This is the main metric of Enhanced Ecommerce module that tracks placed orders. The following JavaScript code is performed when the user places the order:

<script>
  window.dataLayer = window.dataLayer || [];
  dataLayer.push({
    event: 'transactionPush', 
    ecommerce: {
    currencyCode: 'USD',
    purchase: {
      actionField: {
        id: '267519', // Transaction ID        
        affiliation: 'Apple',             	
        revenue: 999.00,
        Tax: 0.00,
        shipping: 0.00
      },
        products: [{
          name: 'iPhone XS Max',
          id: 'A123',
          price: 799.00,
          brand: 'Apple',
          category: 'Smartphones',
          variant: 'Gold',
          quantity: 1
        }]
      }
    }
  });
</script>

With dataLayer variables in Google Tag Manager you can receive data and transfer it to Facebook Pixel. Say, you need to get revenue (cost of order).

Let’s go through the process step by step:

  1. Go to Google Tag Manager.
  2. In the tab “Variables” create two variables (revenue and currency).

  3. To do this choose the tag configuration “Data Layer Variable” and write the whole path that we indicated above.
  4. For the first variable the path would be ecommerce.purchase.actionField.revenue:

    Create the second variable the same way but with the name ecommerce.currencyCode.

Now let’s create sending of the completed purchase directly to Facebook Ads. To do so go to the tab “Tags”.

  1. Create a tag on Custom HTML level (just like in the standard setting of Pixel in GTM).
  2. Insert Pixel code into the code for the event “Purchase”.
<script>
fbq('track', 'Purchase', {
value: {{ecommerce.purchase.actionField.revenue}},
currency: {{ecommerce.currencyCode}}
});
</script>
  1. In the trigger set the event that will turn on in the moment of checkout.

Now during the transaction the data will be captured from DataLayer and sent to Facebook Pixel with the help of GTM.

Important note: described trigger should correspond with the trigger that sends Enhanced Ecommerce data to Google Analytics.

Tracking Custom Events

Custom events are actions that are not included in the list of standard events in Facebook library. You pick the name for your custom events yourself and set each one due to your goals. With custom events you can track and analyze unconventional user actions and create audiences based on this data.

Custom events are tracked by calling a Pixel function fbq(‘track’, ‘trackCustom’);, with a unique name of the event for a specific action indicated. Maximum length for a name is 50 symbols.

Just like standard events, custom events help track actions of your website visitors. However only if they work together you’ll get a full output from Facebook Pixel.

Examples of custom conversions:

  • sign up for a newsletter;
  • going through onboarding; 
  • aha moment in a product

For instance, you want to track users who signed up for a newsletter. In this case the code for the event can look like this:

<script>
fbq(‘trackCustom’, ‘Newsletter’);
</script>

You can also send additional data like a name or a form identifier of the newsletter (in order to use data for user segmentation later on):

<script>
   fbq('trackCustom', 'Newsletter', {
   form_name: 'Google Analytics Tips',
   form_id: 'gf410'
});
</script>

Where:

  • Newsletter — name of the event (you can pick any name).
  • form_name and form_id — additional parameters for the event. There can be as many as you need.

Setting the event tracking on Google Tag Manager side is the same as for standard events.

Note: to track actions correctly the main Pixel code has to load BEFORE the event code starts loading. Otherwise Pixel won’t register and track it. 

Conversion window (attribution)

This is a tool that passes to Facebook the information on data of which period should be best to use for a more effective marketing campaign optimization.

“Conversion window” shows whether the action, which the user made after a certain time after viewing the ad or clicking on it, is relevant for further ads optimization. 

Within the selected time frame Facebook “tracks” the user that interacted with the ad. The system tracks site visits and ads view. If within the stated time period the user that saw the ad places an order via your link, Facebook will count it as conversion. Even if the purchase was made via another source like search results, the system will consider that the ad influenced the user. So the action can be used as an additional source for optimization.  

Early in 2021 changes were made to attributions settings.

Apple released an updated iOS 14, which limits receiving and processing conversion events registered by instruments like Facebook Pixel. Now Facebook has to request permission for changing the conversion events on Apple devices with iOS 14 via AppTrackingTransparencе framework. In response to new Apple rules, Facebook changed attribution settings.

New attribution window setting is presented on an ads group level and will substitute settings on the account level. It is available in the department “Optimization and display” on the campaign creation level. 

Earlier in Facebook Ad Manager there were by default two parameters for tracking users: “After clicking on the ad” and “After viewing and clicking on the ad”. For both parameters time of tracking can be chosen — either one day or seven days.

After the update the setting supports four attribution windows:

  • one day after the click; 
  • seven days after the click;
  • one day after the click and one day after the view;
  • seven days after the click and one day after the view.

iOS 14 campaigns, aimed at app installation, will use API SKAdNetwork framework from Apple. Until Apple implements AppTrackingTransparency (АТТ), the attribution window “Seven days after the click and one day after the view” will be used by default.

The above means you have to necessarily take two actions:

  1. Confirm domain. Facebook prepared an instruction for it.  
  2. Set prioritization of events. 

Let’s check how to set prioritization of events:

  1. n Events Manager go to the tab “Data Sources”.
  2. Choose created Pixel and open the tab “Aggregated Event Measurement”.
  3. In the tab you’ll be offered to confirm the domain if you haven’t done so yet. If the domain is confirmed, Events Manager will offer you to choose priority for your events.

You can indicate your Pixel and select a standard or a custom event. You can pick up to eight slots of events. There’s low and high priority. How does it work? 

Apple will ask users who enter the site from a device with iOS 14 and later versions whether they allow to share the data with the company.

  • If the user allows data sharing, their actions on the site will be sent to Facebook Pixel.
  • If the visitor denies data sharing, Facebook Pixel will receive only one action with the highest priority. 

For instance, you own an online store. You set several events:

  • view product card,
  • add to cart,
  • complete transaction.

You’ll have to set priority for the events depending on your sales funnel where the highest priority should be the final goal, i.e. Purchase. Then Add to cart follows and the lowest priority would be for View product card.

This is how you’ll still get to track your most valuable conversion even if the user with a device on iOS 14 or later versions didn’t permit to share data (the aggregated data will still be transferred).

Facebook Pixel Helper

This is an extension for Google Chrome that helps track whether the implemented Facebook Pixel works correctly. The plugin shows Pixel ID installed on a website and conversions that go to Facebook Ads. It is convenient to use for debug and removing mistakes in Pixel code.

Install Facebook Pixel Helper — its icon will appear next to the address bar. To launch the extension go to your website and click on the plugin icon. There will be a pop-up window with information which Pixels and events were found on the page and whether they loaded successfully.

If you added standard events to Pixel code on some pages, run a test conversion for each. This is how you make sure that the events work correctly — get loaded on the relevant page and after the specific action. For instance, to test the event “Contact” send a message to chat on a website and to test the event “Add to Cart” add an item to the cart.

FAQ

  1. How many Pixels can you create on Facebook? Within one Business Manager account you can create up to a hundred Pixels. However as a rule for your work you’ll only need one.
  2. Is Facebook Pixel free?
    Yes, it’s a free plugin developed by Facebook.

This block will be expanded. If you have questions about Facebook Pixel and its setting, as well as standard or custom events, feel free to ask in the comments to this guide.