How to Install Meta Pixel - Complete Guide

By Nico
November 26, 2025·5 min read

The Meta Pixel tracks what visitors do on your website and sends that data to Facebook. This lets you measure ad performance, build retargeting audiences, and run optimized campaigns.

I recommend installing your pixel today, even if you're not running ads yet. The pixel starts collecting visitor data immediately. When you're ready to launch campaigns, you'll have a warm audience instead of starting from zero.
Nuxt
Next.jsSoon
React
VueSoon
JavaScript
HTML

Getting Your Pixel ID

Before installing, grab your Pixel ID from Facebook:

  1. Go to Facebook Events Manager
  2. Click Data Sources → select your pixel (or create one)
  3. Copy the Pixel ID (15-16 digit number)

Finding your Pixel ID in Facebook Events Manager

Facebook sometimes calls this "Dataset ID" — it's the same thing.

JavaScript Installation

For any JavaScript project, I recommend using the Meta Pixel NPM package:

npm install @adkit.so/meta-pixel

Then initialize the pixel:

main.js
import META from '@adkit.so/meta-pixel';

META.init({
    pixelIds: ['YOUR_PIXEL_ID'],
    autoTrackPageView: true,
    debug: true, // Remove in production
});

Tracking Events

main.js
import META from '@adkit.so/meta-pixel';

// Standard events
META.track('ViewContent', { content_id: 'product-123' });
META.track('AddToCart', { value: 29.99, currency: 'USD' });
META.track('Purchase', { value: 99, currency: 'USD' });

// Custom events
META.trackCustom('WatchedVideo', { video_id: 'abc' });

You can verify events are firing with the Meta Pixel Helper Chrome extension:

ViewContent event with parameters in Meta Pixel Helper

Available Standard Events

  • PageView
  • ViewContent
  • AddToCart
  • AddToWishlist
  • InitiateCheckout
  • Purchase
  • Lead
  • CompleteRegistration
  • Subscribe
  • StartTrial
  • Search
  • Contact
  • Donate
  • Schedule

Use standard events whenever possible — they work better for ad optimization than custom events.

Manual <script> Installation

If you can't use npm, add this script directly to your HTML <head>:

index.html
<!-- Meta 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');
    fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=998515319079495&ev=PageView&noscript=1" /></noscript>
<!-- End Meta Pixel Code -->

Replace YOUR_PIXEL_ID with your actual Pixel ID.

For single-page apps, you'll need to manually call fbq('track', 'PageView') on route changes. That's why I recommend using the JavaScript NPM package package if possible.

Verify Your Installation

Use the Meta Pixel Helper Chrome extension to verify your pixel is firing correctly. It shows a green badge when pixels are detected on the page.

Meta Pixel Helper showing detected pixel

Next Steps

Once your pixel is installed:

  1. Create audiences in Events Manager based on visitor behavior
  2. Set up conversions to track purchases, signups, or other goals
  3. Run optimized ads using your pixel events as optimization targets
Share on:
Photo of Nico

Article by

Nico Jeannen

Hey! I'm the founder of AdKit. I've been doing ads for almost 10 years. I grew and sold my 2 previous startup using ads. Then I created AdKit to make ads accessible to everyone.