How to add a Facebook pixel to Shopify (and where not to paste it)
Add a Meta (Facebook) pixel to Shopify with the Facebook & Instagram app, a custom pixel in Customer events, or a tracking app. Then test it with a real order.
The easiest way is Shopify’s free Facebook & Instagram app: install it, turn on customer data sharing in its settings and connect your Meta pixel (or create one there). If you’d rather do it by hand, add a custom pixel under Settings → Customer events with Meta’s code wired to Shopify’s events. Don’t paste the pixel into your theme. It can’t see checkout, so it never reports a purchase.
On Shopify, the Meta (Facebook) pixel belongs in Customer events, not in theme.liquid or
the old Additional Scripts box. Checkout and the Thank you page don’t load your theme, so
theme code sends page views and add-to-carts but no Purchase. Three things add the pixel the
right way: the Facebook & Instagram app, which sets it up for you; a custom pixel, where you
map Shopify’s events to Meta’s; or a tracking app with its own pixel. Pick one, then test it
with an order in Events Manager.
Before you start
You’ll need:
- Admin access to your Shopify store, including Settings.
- A Meta pixel, or permission to create one. Events Manager now calls a pixel a dataset. The Facebook & Instagram app can also create one for you.
- Full control of your Facebook Page and business portfolio, for the Facebook & Instagram app. Shopify won’t list a Page your business portfolio doesn’t own.
- Your pixel ID, for a custom pixel. It’s the long number under the pixel’s name in Events Manager.
Then spend two minutes making sure nothing is already sending events. Look in Settings →
Customer events for app pixels and custom pixels, and search your theme code for fbq(.
An old install plus a new one means Meta counts events twice. If you find anything, our
guide to finding duplicate Meta pixels
walks through removing it.
Which way to pick
| Facebook & Instagram app | Custom pixel | Tracking app | |
|---|---|---|---|
| Cost | Free | Free | Varies |
| Code | None | Paste and edit JavaScript | None |
| Sends Purchase | Yes | If you wire it up | Depends on the app |
| Conversions API | At Enhanced or Maximum | No | Depends on the app |
| Who helps when it breaks | Shopify and Meta | Nobody (unsupported) | The app’s developer |
For most stores the Facebook & Instagram app is the answer. Use a custom pixel when you need control over exactly what gets sent, or you can’t use the app (for example, the pixel belongs to a business portfolio you can’t connect). A tracking app makes sense when you want something the app doesn’t give you, and you’ll make it the only source.
Option 1: the Facebook & Instagram app
Meta makes this app, and Shopify treats it as a sales channel, so once it’s installed you’ll find it under Sales channels rather than in your list of apps.
First, install it and connect your Meta account:
- In Shopify admin, go to Settings → Apps and sales channels, open the Shopify App Store and search for Facebook & Instagram. Click Add channel (or Add app).
- Click Start set up, then Connect account, and log in to Facebook.
- Connect the assets it asks for: your business portfolio, Page and ad account. Accept the terms and click Finish setup.
Then add the pixel:
- Go to Sales channels → Facebook & Instagram → Settings, then Data sharing settings.
- Turn customer data sharing on. Shopify won’t let you add a pixel until you do.
- Choose a level: Standard, Enhanced or Maximum.
- Click Connect next to your pixel, or Create new to make one, then Confirm.
The level matters more than it looks. Standard is the browser pixel only, so an ad blocker can stop it. Enhanced and Maximum add Meta’s Conversions API, which sends events from Shopify’s servers, and they share customer details like name, email, phone and location with Meta for matching. If you pick one of those, say so in your privacy policy. How to set up Meta Conversions API on Shopify explains the levels in more detail.
Shopify’s labels move around a bit, and its own help pages don’t always agree on them (“Data sharing settings” in one place, “Share data settings” in another). If a menu name doesn’t match, look for the same idea one click away.
Once data sharing is on, the app sends the standard shopping events (page views, product views, add-to-carts, checkouts and purchases among them) without any code. If you had an old pixel in your theme, delete it now, or every storefront event gets counted twice.
Option 2: a custom pixel in Customer events
This is the “manually add the pixel” route, and it’s the one old guides get wrong. You don’t paste Meta’s snippet into the theme. You paste it into a custom pixel, which runs in a sandbox on every page, checkout included, and you tell it which Shopify events to send.
Shopify warns that custom pixels need JavaScript knowledge and aren’t covered by its support. That’s fair: if the code breaks, nothing tells you.
- Go to Settings → Customer events and click Add custom pixel.
- Give it a name you’ll recognise later, like “Meta pixel”, and click Add pixel.
- Leave Customer privacy on its default, which requires marketing and analytics permission. That’s the right setting for a Meta pixel.
- Paste the code below into the Code window and put your pixel ID where it says
YOUR_PIXEL_ID. - Click Save, then Connect pixel. Until it’s connected, it does nothing.
Here’s the code. The top part is Meta’s base code with the <script> and <noscript> tags
taken out, because the sandbox only runs JavaScript. The rest listens for Shopify’s events and
sends the matching Meta event:
!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");
analytics.subscribe("page_viewed", () => {
fbq("track", "PageView");
});
analytics.subscribe("product_viewed", (event) => {
const variant = event.data?.productVariant;
fbq("track", "ViewContent", {
content_ids: [variant?.id],
content_type: "product",
value: variant?.price?.amount,
currency: variant?.price?.currencyCode,
});
});
analytics.subscribe("product_added_to_cart", (event) => {
const line = event.data?.cartLine;
fbq("track", "AddToCart", {
content_ids: [line?.merchandise?.id],
content_type: "product",
value: line?.cost?.totalAmount?.amount,
currency: line?.cost?.totalAmount?.currencyCode,
});
});
analytics.subscribe("checkout_started", (event) => {
const checkout = event.data?.checkout;
fbq("track", "InitiateCheckout", {
value: checkout?.totalPrice?.amount,
currency: checkout?.currencyCode,
});
});
analytics.subscribe("checkout_completed", (event) => {
const checkout = event.data?.checkout;
fbq("track", "Purchase", {
value: checkout?.totalPrice?.amount,
currency: checkout?.currencyCode,
}, { eventID: checkout?.order?.id });
});
Purchase uses the order ID as its event ID, so if the same order is ever reported twice, Meta can merge the two. The content IDs are variant IDs. If you run catalog ads, check that your catalog uses the same IDs, or Meta won’t match the products. Shopify’s own example in its help center adds Search and AddPaymentInfo too, if you want them.
Keep in mind that this is browser only. A custom pixel doesn’t use the Conversions API, so ad blockers and shoppers who leave before the Thank you page loads will cost you some events.
Option 3: a tracking app
Most tracking apps in the Shopify App Store install their own pixel through Customer events when you install them, so there’s no code to paste. Setup is usually: install, log in with Facebook, choose the pixel, and check that events arrive. Many of them send events from their own server through the Conversions API.
They differ a lot in what they send and what they show you, so read the listing before you install. And treat the app as a replacement, not an extra: if the Facebook & Instagram app’s data sharing is also on for the same pixel, Meta will usually count each sale twice. Facebook and Instagram app Conversions API vs a third-party app helps you decide whether one is worth paying for.
Why the theme is the wrong place
Most guides from a few years ago say to paste the base code into theme.liquid and the
Purchase snippet into Settings → Checkout → Additional scripts. That setup is broken now:
- Your theme doesn’t load in Shopify’s checkout or on the Thank you page, so theme code never sees a purchase.
- Shopify has switched off Additional Scripts on the Thank you and Order status pages for every plan.
The result is a pixel that looks fine on product pages and reports no sales. If that’s what you’re seeing, the guide to a Purchase event that isn’t firing covers the fix.
Check that it works
Don’t trust the Meta Pixel Helper extension for this. Pixels in Customer events run in a sandbox it often can’t see into, so it can say “no pixel found” on a store where everything works. Use Events Manager instead:
- In Events Manager, open your pixel and go to Test events.
- Enter your store’s URL and open it from there.
- View a product, add it to the cart and start checkout. Each step should show up in the list within a few seconds.
- Place a real order, or a test order with Shopify Payments in test mode, and wait for the Thank you page to load. Purchase should appear.
If you want a second opinion, open your store in Chrome with the browser’s developer tools on
the Network tab and filter by facebook.com/tr. Every row is one event leaving the
browser, with your pixel ID in it. Two PageView rows for one page load means two sources are
running.
Give the main Events Manager overview a day of real traffic before you judge it. Then compare a week of Purchase events with a week of Shopify orders. Meta will usually show somewhat fewer, because shoppers who decline marketing on your cookie banner aren’t tracked, and some leave before the Thank you page.
Where SuperPixel fits
SuperPixel is the tracking app I build, so it’s an Option 3. Most stores adding a pixel for the first time don’t need it, and the Facebook & Instagram app is a good place to start.
It installs from the Shopify App Store and adds its own pixel through Shopify’s customer events right after install, so there’s no theme code and no custom pixel to look after. A setup checklist takes you through installing the pixel, connecting an ad account, choosing which pixel gets conversions and confirming events are arriving.
You connect Meta by logging in with Facebook, and it finds the ad accounts and pixels you can access, including ones owned by a Business Manager. It can send to more than one pixel, each switched on or off separately.
It sends page views, product views, add-to-carts, checkouts started and purchases to Meta’s Conversions API from its own server, so an ad blocker that blocks Meta’s browser script doesn’t stop them. Each purchase is matched to Shopify’s paid order, so a reloaded Thank you page counts once. The Live Events page shows recent events, which pixels each went to, and why one wasn’t sent.
The limits: it doesn’t send Search or AddPaymentInfo, or customer details like email and phone, so the Facebook & Instagram app at Enhanced or Maximum shares more for matching. It only sends events for shoppers who allowed marketing. Orders its pixel never saw aren’t sent to Meta. It has no setting for Meta’s test event code, so check its events on the Live Events page rather than in Test events. And it won’t turn off your other Meta sources; that’s your job.
It costs $29 a month or $232 a year, billed through Shopify, and your first 5 purchases are sent free so you can test it.
FAQ
Can I still paste the Facebook pixel into theme.liquid?
You can, but it only runs on storefront pages, so Meta gets page views and add-to-carts and never a purchase. Use the Facebook & Instagram app or a custom pixel in Customer events instead, and delete any old theme code once the new one is live.
Do I need the Conversions API as well as the pixel?
Not to get started. A browser pixel works, but ad blockers and closed tabs cost you some events. The Facebook & Instagram app adds the Conversions API at Enhanced or Maximum, and many tracking apps send events server-side too.
Can I add two Meta pixels to one Shopify store?
Yes, if they’re different pixels doing different jobs. The Facebook & Instagram app connects one pixel at a time, so a second one usually goes in a custom pixel or through an app that sends to several. What you want to avoid is the same pixel ID installed twice.
Why does Pixel Helper say no pixel was found?
Because pixels in Customer events run in a sandbox the extension often can’t see. Check Test events in Events Manager, or the Network tab, before you assume something’s broken.
How long until events show up in Events Manager?
Test events show browser events within seconds. The main overview can lag, so give it an hour, and a full day before comparing totals with Shopify.
Try it on your store
If you’d like to see each event go out, and the reason when one doesn’t, you can try SuperPixel free on your first 5 purchases and watch the Live Events page while you place a test order. Stuck on one of the other options? Email me at [email protected] and I’ll take a look.