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.
Getting Your Pixel ID
Before installing, grab your Pixel ID from Facebook:
- Go to Facebook Events Manager
- Click Data Sources → select your pixel (or create one)
- Copy the Pixel ID (15-16 digit number)
![]()
JavaScript Installation
For any JavaScript project, I recommend using the Meta Pixel NPM package:
npm install @adkit.so/meta-pixel
Then initialize the pixel:
import META from '@adkit.so/meta-pixel';
META.init({
pixelIds: ['YOUR_PIXEL_ID'],
autoTrackPageView: true,
debug: true, // Remove in production
});
Tracking Events
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:
![]()
Available Standard Events
PageViewViewContentAddToCartAddToWishlistInitiateCheckoutPurchaseLeadCompleteRegistrationSubscribeStartTrialSearchContactDonateSchedule
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>:
<!-- 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.
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.
![]()
Next Steps
Once your pixel is installed:
- Create audiences in Events Manager based on visitor behavior
- Set up conversions to track purchases, signups, or other goals
- Run optimized ads using your pixel events as optimization targets
