Analytics & Reporting

Facebook Pixel: Setup and Conversion Events

A step by step guide to installing the new Facebook pixel, tracking conversion events and moving away from the older pixels before they are retired.

Quick answer: The Facebook pixel is a short piece of JavaScript you add to every page of your site. It records visits and actions so you can measure which ads lead to sales or enquiries, build audiences of past visitors and let Facebook optimise ads for conversions. Facebook introduced a single, unified pixel late last year to replace the separate Custom Audience pixel and conversion tracking pixel, which are being phased out. Install the base code on every page, add standard events such as Lead or Purchase where those actions happen, then check it with the Pixel Helper extension.

If you have run Facebook ads for a while, you may have two older pieces of code on your site: one for building website Custom Audiences and one or more conversion tracking pixels, often one per goal. The new pixel combines both jobs into one code that runs on every page, with events for the important actions. Facebook has said the older conversion tracking pixel will be retired, so now is a good time to switch rather than wait.

What the pixel does

Once installed, the pixel lets you:

  • Measure conversions. See how many leads, sign ups or purchases came from people who saw or clicked your ads, and what they were worth.
  • Optimise delivery. Tell Facebook to show ads to the people most likely to complete a particular action, rather than just to click.
  • Build audiences. Create Custom Audiences of people who visited certain pages or took certain actions, so you can show them relevant ads later, and create lookalike audiences based on them.

Step 1: Get your pixel code

In Ads Manager, open the Pixels section under Tools. If you do not have a pixel yet, create one; each ad account has a single pixel. Facebook will show you the base code.

Step 2: Install the base code on every page

The base code goes in the <head> section of every page on your site, just before the closing </head> tag. It loads the pixel script and sends a PageView event each time a page loads.

Ways to install it:

  • Directly in your theme or template header file, if a developer manages the site.
  • Through Google Tag Manager, using a Custom HTML tag that fires on all pages. This keeps marketing tags in one place.
  • Through a plugin or platform setting. Many WordPress plugins and ecommerce platforms have a field for the pixel ID.

If you still have the old Custom Audience pixel installed, the new pixel replaces it. Remove the old code once the new one is working, so you are not loading both.

Step 3: Add standard events

Events tell Facebook that a particular action happened. The new pixel supports nine standard events:

  • ViewContent: a key page is viewed, such as a product page.
  • Search: a search is made on your site.
  • AddToCart: an item is added to the cart.
  • AddToWishlist: an item is added to a wishlist.
  • InitiateCheckout: someone starts checkout.
  • AddPaymentInfo: payment details are added during checkout.
  • Purchase: a purchase is completed.
  • Lead: someone submits an enquiry or signs up for something, such as a quote request.
  • CompleteRegistration: a registration form is completed.

Each event is a single line of code that runs after the base code, on the page or at the moment the action happens. For example, on a thank you page after an enquiry form:

fbq('track', 'Lead');

And on an order confirmation page:

fbq('track', 'Purchase', {value: 49.99, currency: 'GBP'});

Pass values for purchases

Including the order value and currency lets Facebook report the value of conversions and calculate return on ad spend. On ecommerce sites, a developer should pull the real order total into the code dynamically rather than hard coding a number.

Use parameters for dynamic ads

If you run product catalogue ads, events such as ViewContent, AddToCart and Purchase should include the product IDs and content type, matching the IDs in your product catalogue. This is how Facebook knows which products each visitor looked at.

Events on actions, not pages

Not every action has its own page. If a form shows a thank you message without loading a new page, fire the event when the form submits successfully. In Tag Manager, that can be done with a trigger on the form submission or on a data layer event pushed by the site.

Step 4: Create custom conversions

If you cannot add event code, or want to track something not covered by standard events, use custom conversions. In Ads Manager, create a custom conversion based on a URL rule, such as “URL contains /thank-you/”, and give it a category and optional value. It uses the base pixel’s page views, so no extra code is needed.

Custom conversions are also useful for splitting one event into several goals, for example separate conversions for different thank you pages.

Step 5: Check it works

Facebook Pixel Helper

Install the Facebook Pixel Helper extension for Chrome. Visit your site and it shows which pixels and events fired on each page, along with any errors such as the code being placed incorrectly or firing twice.

Pixel activity in Ads Manager

The pixel page in Ads Manager shows recent activity and the events received. After testing a purchase or enquiry, check that the event appears.

Common problems

  • The base code is missing on some templates, such as a checkout hosted on a different domain or a separate landing page tool.
  • Events fire before the base code loads, so they are lost.
  • Events fire twice, because the code is in both the theme and Tag Manager.
  • Purchase fires on every reload of the confirmation page, inflating results.
  • The value is wrong, because it is hard coded or includes tax and shipping inconsistently.

Use the data well

Once the pixel is working:

  • Choose the right optimisation goal. For lead generation campaigns, optimise for the Lead event rather than clicks.
  • Build useful audiences. For example, people who viewed a service page in the last 30 days but did not enquire.
  • Exclude converters. Stop showing an offer to people who have already taken it.
  • Compare with your own analytics. Facebook counts conversions after both clicks and views, within a time window, so its numbers will differ from Google Analytics. Know which settings you are comparing.

If you collect leads directly on Facebook rather than on your website, see our guide to Facebook Lead Ads, which covers getting those leads into your CRM. If your site is a single page application, the pixel needs the same care as Google Analytics with virtual page views; our guide to single page application tracking explains the approach.

Privacy

The pixel sets cookies and sends data about visits to Facebook. Your privacy policy should explain this, and in the EU you need to follow the cookie consent rules that apply to advertising cookies. Do not send personal information such as names, email addresses or health details in event parameters or URLs.

FAQ

Do I need a separate pixel for each campaign?

No. One pixel covers your whole site and every campaign in the ad account. Events and custom conversions separate the goals.

What happens to my old conversion pixels?

They still work for now, but Facebook plans to retire them. Set up the new pixel and events, check they record the same results, then remove the old code.

Can I use the pixel on more than one website?

Yes, but your reports and audiences will mix data from both. Separate ad accounts with their own pixels are often cleaner.

Want tracking you can rely on?

We set up pixels, events and analytics so you can see which ads bring real customers. See how we help you know what’s working.

About the author

Imran M

Leave a Reply

Your email address will not be published. Required fields are marked *

Ready to improve your website?

Let's build a faster, higher performing website.