Last update: Sep 30, 2025·10 minutes read

Meta Pixel Code Example, Setup, and Best Uses

Meta Pixel may seem technical, but it’s simpler than it looks. We explain what the Meta Pixel code is, how to install it, and how to troubleshoot common errors. You’ll also see a meta pixel code example and learn how to use Pixel data for retargeting, audience building, and measuring ad performance.

Damaris Hinga
Written by Damaris Hinga , Digital Marketing Specialist
Leszek Dudkiewicz
Reviewed by Leszek Dudkiewicz , Digital Growth Manager
As seen on:
Table of Contents
    Share:

    One of the biggest benefits of running Facebook ads, besides reaching millions of people, is the amount of data you can collect. This is all made possible by the Meta Pixel code (formerly Facebook Pixel code).

    Today, we’ll show you a Meta Pixel code example, explain how to install it, and cover some troubleshooting tips you may need along the way. 

    We’ll also get into a few handy ways to use this tool for your marketing needs.

    Key takeaways

    • The Meta Pixel code is a small piece of JavaScript that tracks visitor actions on your website and sends that data back to Meta.
    • You can use Meta Pixel data to create custom audiences based on behaviors such as page views, button clicks, or cart abandonment.
    • Setting up the Pixel involves three main steps: creating the Pixel in the Events Manager, installing it on your website, and configuring events.
    • Troubleshooting tools like the Meta Pixel Helper extension make it easy to test whether your Pixel is active and recording events correctly.

    Turn product images into catalog ads. Automatically!

    What is a Meta pixel code?

    A Meta Pixel code is a small piece of JavaScript that Facebook provides. You add it to your website or app to track what visitors do while they’re there.

    Every time someone takes an action you care about, such as clicking a button, making a purchase, or signing up, it’s recorded as an event. The Pixel then sends that information back to Meta, where you can use it for Facebook ads and audience creation.

    Meta Pixel collects valuable details about your visitors and how they interact with your site. These include, but are not limited to:

    1. Visitor Info: Basic details like browser type, pages visited, referral source, and general location. This information helps you build the demographic data of your audience.
    2. Pixel and Cookie Data: Tracks visits specifically tied to your Meta Pixel and Facebook cookies, linking visitor behavior to your ad campaigns.
    3. Button Clicks: Records actions like clicks on ‘Buy,’ ‘Sign Up,’ or other call-to-action buttons, along with the pages visited afterward.
    4. Custom Data (Optional): Lets you send extra information relevant to your business, such as purchase value, page type, or other conversion metrics.
    5. Form Field Names: Notes the types of fields visitors interact with (email, address, quantity). It doesn’t capture what’s entered unless you configure Advanced Matching or custom tracking.

    Put simply, the Meta Pixel helps you track visitor behavior, measure ad performance, and collect data to improve ad conversions.

    Here’s an example of what the Meta Pixel code looks like:

    <!-- Facebook Pixel Code -->
    <script>
      !function(f,b,e,v,n,t,s)
      {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
      n.callMethod.apply(n,arguments):n.queue.push(arguments)};
      if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
      n.queue=[];t=b.createElement(e);t.async=!0;
      t.src=v;s=b.getElementsByTagName(e)[0];
      s.parentNode.insertBefore(t,s)}(window, document,'script',
      'https://connect.facebook.net/en_US/fbevents.js');
      fbq('init', '
    {your-pixel-id-goes-here}
    '); fbq('track', 'PageView'); </script> <noscript> <img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=
    {your-pixel-id-goes-here}
    &ev=PageView&noscript=1"/> </noscript> <!-- End Facebook Pixel Code -->

    What can you do with a meta pixel code?

    There are many ways to use the Meta Pixel code. The most common one is retargeting or remarketing.

    For example, if you browse sneakers on a website using your laptop, you might add a pair to your cart to save for later. Later that day, when you open Facebook or Instagram on your phone, you’ll likely see ads for the same sneakers or similar ones. 

    That’s retargeting, and it’s made possible by the Meta Pixel.

    Let’s look at more meta pixel uses in detail.

    Build custom audiences

    Meta Pixel is an advanced technology that is pretty great at helping you create audiences for your ads

    For example, you can create an audience of people who viewed your website, clicked a certain page, or abandoned their carts. And we’re just scratching the surface with these examples. 

    You can go further by segmenting audiences based on how often they visit, how much time they spend on certain pages, or whether they completed fundamental actions like signing up for a newsletter.

    Create lookalike audiences

    Once you have those custom audiences, Meta studies the behavior of your best customers and then finds new people who share similar interests and habits.

    If your custom audience is made up of people who have already bought from you, Meta will analyze what they have in common and build a lookalike group of fresh prospects who are likely to be interested in your business too.

    For a business, this is powerful because it lets you scale without losing touch with a relevant audience. Rather than guessing who might want your product or service, you’re expanding into circles of people who are already primed to care.

    Measure ad performance

    Meta Pixel also helps you see whether your ads are actually bringing in an ROI. It shows what happens after someone interacts with your campaign. 

    Did they view a product? Add something to their cart? Sign up for a newsletter? Complete a purchase?

    Because the Pixel links actions on your website back to the ads that drove them, it gives you a better picture of which campaigns deliver effective results

    If one ad is bringing in traffic but no conversions, you’ll know it’s not working as intended. If another ad is consistently leading to sales, you’ll know where to put more of your budget.

    Understand the buyer’s path to conversion

    In our earlier example, you started your search on your laptop, and later ended up seeing ads on your phone for the same or similar sneakers. 

    That’s Meta Pixel at play. 

    Because it can connect activity across devices, it shows the complete path a customer takes before buying. The Pixel records if someone clicked an ad, viewed a product page, left, returned through a search, and then completed a purchase. 

    All these details show which steps within your site result in sales and which ones cause people to drop off. That knowledge helps you adjust your campaigns and put your budget into the channels that close deals.

    Meta pixel set up and installation 

    The setup process has #3 main steps:

    • Create a Pixel code on Facebook
    • Set up the Pixel on your website
    • Configure Facebook events

    We’ll go through each of these step by step. 

    A. Create a pixel code on Facebook

    1. In Meta Business Suite Manager, click the hamburger menu and select All Tools.
    2. Open Events Manager, then choose Connect Data Source. Select Web because it tracks website visits.

    connect-data-source.PNG

    1. Name your dataset, preferably something related to your business, and click Create. You’ve created a dataset, but now, it’s time to set up the pixel so you can get the base pixel code.  

    name-your-data-set.PNG

    1. Go to Datasets, on the left-hand side, select your dataset, and scroll down to the section for setting up Meta Pixel. 

    meta-pixel-setup.PNG

    1. Choose Set up Meta Pixel to get your base code, and then from there, you can proceed to the next step, which now involves installing the code on your website. 

    setting-up-meta-pixel.PNG

    B. Set up the Facebook Pixel on your website

    After creating the Pixel, choose how to install it. You can do it manually or through a partner integration.

    installing-meta-pixel-to-website.PNG

    Let’s start with manual installation

    Manual installation:

    1. Copy the base code.

    copy-base-code.PNG

    1. Paste the code between the <head> and </head> tags of your webpage. If other code already exists there, place the Pixel code underneath it, but above </head>. Add the base code to every page of your site.
    2. Refresh your website to save and confirm the changes.

    For the Partner integration, the process is much simpler since it’s just a matter of granting permissions. There are partner options for Shopify, WordPress, Bigcommerce, Google Tag Manager, etc. 

    partner-integration-for-meta-pixel-code.PNG

    For most partners, it will involve adding a plugin of some sort to make the pixel setup possible. 

    For example, on WordPress, you can install Meta Pixel for WordPress and directly connect your pixel, and even set up ads from your site. 

    If your Pixel is active, it will show as active under Datasets, and you’ll start to see page views recorded after setup. Just like this example below: 

    active-pixel-code.PNG

    C. Configure Facebook events

    After your Pixel is installed, you should start to see events appear in Events Manager. 

    These events reflect the actions people take on your site, such as viewing a page, clicking a button, or completing a purchase.

    If you want more control over what you track, you can set up custom events using the Event Setup Tool. This option does not require coding and is one of the easiest ways to manage events. Here’s how to do it:

    1. Open your website in the Event Setup Tool
      Enter your website URL into the setup tool and your site will open in a new browser window and connect directly to your ad account.

    setting-up-events.PNG

    1. Select the events you want to track
      You can choose from Meta’s suggested events or create your own. For custom options, click Track New Button or Track a URL, then follow the on-screen instructions.

    tracking-events-on-website.PNG

    1. Assign an event type
      Decide what action you want to track, such as purchase, initiate checkout, or contact. Each action is logged as a specific event, and that label is what tells Meta how to categorize the interaction. 

    If someone clicks your Contact button, Meta won’t automatically know what that click means until you assign it an event type.

    event-type.PNG

    1. Confirm and finish setup
      After you confirm, the tool will save your settings and activate the event. From that point, every time a visitor performs the action you selected, such as clicking a button or completing a form, Meta records it automatically. 

    You can then use this data to build custom audiences, create lookalike audiences, and refine your targeting for future campaigns.

    Troubleshooting Meta Pixel code

    To test if your Meta Pixel code is working correctly, install the free Meta Pixel Helper Chrome extension. 

    If the icon appears grey, your Pixel is not set up properly. If the Pixel is transmitting data, the grey icon turns blue and shows the number of active events.

    meta-pixel-helper.PNG

    However, if you are having trouble installing Meta Pixel, the issue usually comes down to a few common causes:

    • Pixel not firing or not found
      This often happens when your site is serving cached content, or if there are JavaScript errors blocking the Pixel from running correctly. Installing duplicate codes can also cause the Pixel to break.
    • Pixel not found in Meta Ads Manager
      Even if your Pixel is not active, it should still appear in Ads Manager. If Meta prompts you to create a Pixel when you already have one, it usually means the Pixel is not connected to the specific asset you are working with.
    • Standard events not working

    A common reason for this is that standard events are case-sensitive. If the spelling or formatting is incorrect, the Pixel will not recognize or record the event.

    Best practices for installing the Meta Pixel

    When installing the Meta Pixel, there are two best practices you should follow to stay compliant and improve data accuracy:

    Turn on Advanced Matching

    Advanced Matching allows your Pixel to capture customer details that people share on your website, such as email addresses, phone numbers, or names. This information is encrypted and matched against Meta’s user database to identify more of your site visitors on Facebook and Instagram.

    And as a result, Facebook will have more precise data to help you create custom or lookalike audiences. 

    Add a transparent cookie notice to your site

    Since the Pixel collects data through cookies and similar technologies, you must clearly inform visitors and give them a way to control their preferences. A good cookie notice should:

    • Tell users that your site collects data using cookies and may share it with third parties like Meta.
    • Explain that the data can be used for analytics, ad targeting, and delivering more relevant ads.
    • Provide links or tools where users can learn more and opt out if they wish.

    Create Catalog Ads with Your Product Data

    No cards. No trial. No hidden fees. It’s that simple.

    Final thoughts

    As you can see, setting up a Meta Pixel code is not as complicated as it seems. Provided that you follow all the instructions furnished by Meta, you should have the code set up in just a few minutes. 

    Setting up the Meta pixel is just one part of your Facebook ads journey. 

    You’ll also need to nail down your audience targeting, and more importantly, your ad creatives

    Cropink can help with the latter. To learn more about how we help businesses create ad creatives at scale for catalog ads, visit Cropink.com

    FAQs

    How do I see my meta pixel code?

    You can view your Pixel code inside Meta Events Manager. After creating your Pixel, go to your dataset and look for the setup section. The full code will be available there for manual installation if you need to copy and paste it into your site.

    Where can I get my FB pixel ID?

    Your Pixel ID is shown in Events Manager under the dataset details. It is a string of numbers linked to your Pixel and is also included inside the base code if you install it manually.

    Does Meta Pixel slow down the site?

    The Meta Pixel is a lightweight piece of JavaScript that loads asynchronously, meaning it runs in the background without blocking your website from loading.

    How many Facebook Pixels can I have?

    Each ad account can create multiple Pixels. Many businesses use one main Pixel, but you can set up more if you manage different websites or want to separate data for different campaigns.

    Do you need a developer to set up the Pixel?

    Not necessarily. You can install the Pixel yourself by copying the base code into your site’s header, or by using a partner integration such as WordPress or Shopify. If your website has a custom setup or more advanced tracking requirements, you may find it helpful to involve a developer.

    Damaris Hinga
    Written by Damaris HingaDigital Marketing Specialist

    Damaris is a Digital Marketing Specialist who writes about digital marketing and performance marketing. At Cropink, she creates data-driven content to help businesses run better ad campaigns for better performance and ROI.

    Follow me:LinkedIn
    Leszek Dudkiewicz
    Reviewed by Leszek DudkiewiczDigital Growth Manager

    Leszek is the Digital Growth Manager at Feedink & Cropink, specializing in organic growth for eCommerce and SaaS companies. His background includes roles at Poland's largest accommodation portal and FT1000 companies, with his work featured in Forbes, Inc., Business Insider, Fast Company, Entrepreneur, BBC, and TechRepublic.

    Follow me:LinkedIn
    What is Cropink?

    Cropink is an app that turns raw product feed into appealing Facebook ads enriched with product data. It helps to drive engaging campaigns without creative limitations and keeps everything in sync.

    Beautify your product catalog in minutes

    No credit card required

    What is Cropink?

    Cropink is an app that turns raw product feed into appealing Facebook ads enriched with product data. It helps to drive engaging campaigns without creative limitations and keeps everything in sync.

    Beautify your product catalog in minutes

    No credit card required

    Related Articles

    Facebook Ads·Last update: Sep 22, 2025
    How to Create Good Facebook Ads: A Step-by-Step Guide for Success [2025]

    Running Facebook ads doesn’t have to be expensive or complicated. Learn how to define clear objectives, craft compelling visuals and copy, and target the right audience to maximize your ad performance without overspending.

    Damaris Hinga
    Written by Damaris Hinga , Digital Marketing Specialist
    Facebook Ads·Last update: Sep 22, 2025
    Facebook Ad Credits 101: Enhance Your Campaigns for Less in 2025

    With over 10 million advertisers on Facebook, standing out isn’t easy—but free ad credits can help. Learn how to score and maximize Facebook ad credits to test campaigns, cut costs, and boost performance—without spending a dime.

    Manisha Saini
    Written by Manisha Saini , Data-Driven Marketing Expert
    Facebook Ads·Last update: Aug 25, 2025
    7 Tips to Run a Brand Awareness Campaign on Facebook

    Facebook brand awareness campaigns fail when treated as standalone ads, but they're useful for filling your retargeting pipeline. This guide reveals expert strategies for targeting the right audiences and avoiding the budget-draining mistakes that kill most awareness campaigns before they deliver results.

    Damaris Hinga
    Written by Damaris Hinga , Digital Marketing Specialist
    Facebook Ads·Last update: Aug 13, 2025
    Reasons Your Facebook Ads Not Performing & How to Fix It

    Struggling with Facebook ads? You're not alone—despite reaching 62% of the U.S. population and generating $164.5B in ad revenue, most campaigns fail due to fixable issues. Discover 19 reasons your ads underperform—and how to fix them fast.

    Ansherina Opena
    Written by Ansherina Opena , Digital Marketing Expert
    Facebook Ads·Last update: Aug 13, 2025
    Facebook Ads Targeting: Strategies, Tips & Examples for 2025

    Struggling to make Facebook Ads convert in 2025? With over 3 billion users, targeting—not your product—is often the problem. Learn proven strategies to lower costs, reduce wasted spend, and reach the people most likely to buy.

    Ansherina Opena
    Written by Ansherina Opena , Digital Marketing Expert
    Facebook Ads·Last update: Aug 13, 2025
    CBO Facebook Ads 2025: Complete Guide to Budget Optimization

    Discover how to master Facebook's Campaign Budget Optimization (CBO) in 2025 to boost ROAS and lower costs. With 2.1B users and 13.1B monthly visits, Facebook rewards smart budget strategy—learn how to scale with confidence using real-time algorithmic optimization.

    Ansherina Opena
    Written by Ansherina Opena , Digital Marketing Expert
    Facebook Ads·Last update: Aug 13, 2025
    Meta Ads Manager Tutorial for eCommerce Ads [Beginners Edition]

    This guide walks you through how to use Meta Ads Manager to create and manage Facebook and Instagram ads. Perfect for eCommerce brands looking to move beyond the boost button and get better results from their ad spend.

    Damaris Hinga
    Written by Damaris Hinga , Digital Marketing Specialist
    Facebook Ads·Last update: Aug 13, 2025
    Facebook Ad Budget: How Much to Spend + Benchmarks & Optimization Tips

    Find out everything you need to know about budgeting options in Meta Ads Manager, performance benchmarks, testing strategies, and how to get better results even with a small budget.

    Damaris Hinga
    Written by Damaris Hinga , Digital Marketing Specialist
    Facebook Ads·Last update: Aug 13, 2025
    What Facebook Statistics Reveal About Us in 2025 [You’ll Be Surprised]

    Facebook remains the dominant social media platform with over 3.07 billion monthly active users. From video trends to ad performance and user demographics, these 50+ powerful stats reveal why Facebook is still thriving.

    Manisha Saini
    Written by Manisha Saini , Data-Driven Marketing Expert
    Facebook Ads·Last update: Aug 11, 2025
    A Quick 4-Step Guide to Setting Up Your Facebook Business Manager

    Meta Business Manager can certainly be overwhelming at first, but it doesn’t have to stay that way. This 4-step guide shows you how to set it up, add your assets, and keep everything secure so you can manage Facebook and Instagram marketing with ease.

    Damaris Hinga
    Written by Damaris Hinga , Digital Marketing Specialist
    Facebook Ads·Last update: Aug 11, 2025
    B2B Facebook Ads Guide (2025): Strategies, Funnels & Examples

    With 3 billion+ users and detailed targeting, Facebook is still a powerful B2B channel. This guide breaks down winning ad formats, funnel tactics, and real-world results, including a 492% CTR lift, and why Facebook may outperform LinkedIn for many B2B brands.

    Ansherina Opena
    Written by Ansherina Opena , Digital Marketing Expert
    Facebook Ads·Last update: Aug 11, 2025
    Facebook Ad Placements Guide 2025: Strategies That Work

    Facebook has 3.06B users, ranks as the 3rd most-visited site in 2025, and drove $164.5B in ad revenue last year. Learn how to master its 19 ad placements—from high-engagement Reels to low-CPC right column ads—for maximum ROI.

    Ansherina Opena
    Written by Ansherina Opena , Digital Marketing Expert

    Start with Cropink is easy and free

    No credit card required